is_regexp#

Returns true if the argument is a compiled regular expression as returned by qr//, false if it is not.

Synopsis#

use re qw(is_regexp);
is_regexp(qr/x/);               # 1
is_regexp("x");                 # false
is_regexp(bless {}, "Regexp");  # false

Overloading and blessing do not fool it: it looks at the compiled regexp inside the value, not at the package the value is blessed into. A hash blessed into Regexp is therefore not a regexp, and a qr// object reblessed into another class still is.