'g'=~/g/; my $regex = 'm{}g'; # user input my $text = 'x'; # user input eval qq{ use re 'debug'; print "<\$&>\\n" while \$text =~ $regex; };