If you have variable $foo= qr/a.*b/ and you plug that into another regex like my @matches= /$foo/g it will re-compile the regex just to add the /g switch which doesn't even change the content of the regex, and it will re-compile every time it hits that line of code.
I discovered that while writing my Language::FormulaEngine::Parser where I wanted to take author-supplied regexes and then test them against the current position of the input. If you want these to stay pre-compiled, you need to eval the whole sub where they get used and then call that coderef.
Edit: I was wrong, perl does have special cases for m/$foo/ and m/$foo/g and s/$foo/.../ to avoid re-compiling the regex. However, anything more than that like changing the anchor /\G$foo/gc will trigger a re-compile.
In reply to Re: On the regex pattern variable to be inserted into another
by NERDVANA
in thread On the regex pattern variable to be inserted into another
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |