http://qs1969.pair.com?node_id=1208848


in reply to creating qr from existing regex

Remove the slashes, extract the modifier ("i") (say, in a variable $flags). Keep the core of the regex as a string, in your example that would be .*uba$.

Then put "(?$flags:" in front of it, and ")" behind it. You can use that string ($re) directly as a regex:

$re = "(?:$flags:$core)"; if($input =~ $re) { ... }
edit Oops, one too many colons:
$re = "(?$flags:$core)"; if($input =~ $re) { ... }
You can also turn it into a regex object:
$qr = qr/$re/;