package MyClass; my $cnt; sub new { return bless { cnt => 0 }; } sub gimme_sweet_love { my $self = @_; $self->{cnt} += 1; return "hell yeah" } sub cnt { my $self = @_; return $self->{cnt} } package main; use strict; use warnings; local $\ = $/; my $match = "hell yeah"; my $obj = MyClass->new(); my $re = qr/(??{ ${obj}->gimme_sweet_love })/; print "\$match value:", $match; print "HURAY (m)" if $match =~ m/$re/; print "count = ".$obj->cnt; $match = "hell no"; print "\$match value:", $match; print "HURAY (m)" if $match =~ m/$re/; print "count = ".$obj->cnt; #### $match value:hell yeah HURAY (m) count = 1 $match value:hell no count = 9