my $re = qr/(test)io; # added captures for the example my $class = 'Test'; my $regex = bless(\$re, $class); # bless a reference to the compiled regex my $data = "testing!"; if ($data =~ /$$regex/) { print "Found $1!\n"; } print ref($regex), "\t", ref($$regex), "\n";