I know $regex is a scalar, but the thing it refers to should be considered another type (which ref calls "Regexp").
(Sorry for replying so late!) Indeed the return value of qr is a blessed reference. Thus these "objects" are real objects, and turn out to be autoboxed:
use YAPE::Regex::Explain;
sub Regexp::explain {
print YAPE::Regex::Explain->new(shift)->explain;
}
qr/^.*?Foo(Bar){3,7}\d+/->explain;
In Perl 6 everything is an object too, but currently this is not the case for simple scalars, arrays, etc. unless you use the very interesting autobox module, which used to require a patch, but doesn't anymore, last I checked.