in reply to Use global flag when declaring regular expressions with qr?

You would replace

if ( $row =~ $re )
with
while ( $row =~ /$re/g )

Certain flags control how a pattern is parsed or compiled. Since these are associated with the pattern, they can be provided to qr// and (?:).

These are: msixpodualn.

(It's surprising to find "p" on this list. It's weird. But "p" doesn't do anything since 5.20, so we can pretend it's not there.)


Certain flag affects how the operator itself works. These are provided to the operator itself.

For m//, these are: gc.

For s///, these are: gcer.

msixpodualn can also be provided to these, but they won't be recursively applied to embedded compiled patterns. (The same goes for qr//.)


Therefore, you want to add "g" to the match operator implied by $row =~ $re, and it would result in using $row =~ /$re/g.

Note that /$re/ doesn't cause the pattern to be stringified and re-compiled as it would be if it was interpolated into a larger pattern.