use strict; use warnings; use feature 'say'; my $run=0; sub test { $run++; my $regex = 'm{}g'; # user input my $text = 'xx'; # user input print "--- run $run\n"; pos($text)=0; eval <<"__CODE__"; say pos(\$text),"<\$&>" while \$text =~ $regex; __CODE__ } test(); say "successful /g/" if 'g' =~ /g/; test(); say "successful /x/" if 'x' =~ /x/; test(); my $empty=''; say "successful //" if ' ' =~ /$empty/; test();