in reply to Complex regex and apparent failure of /g option

Without commenting on anything the other two people have said, your use of lexicals and (??{...}) is incorrect. In general, unless you know perlguts you cannot intuit a non-buggy way to use these. Here is a proper way. Its far easier to just use globals - at least you don't need to know internals to reason about their operation.

my $reg; $reg = qr/...(??{sub{$reg}->()}.../;

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊