$pat = "something with (.*?) in it"; $re = qr/$pat/; if ( $line =~ $re ) (or /$re/, same results) { $1 has nothing in it here. nor does $& or $` if ( $line =~ /$pat/ ) { $1 has the matched text in it here } }
The matches will occur orders of magnitude less frequently than the number of uses of the pattern, so the above code still helps performance dramatically, but it's ugly. (I'm trying to avoid taking the step of generating the code and eval'ing when qr// seems to almost do the job.)
I'm using 5.8.1 built from cpan tarball on rh9.
In reply to Is there any way to get at paren matches from qr// by nneul
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |