http://www.perlmonks.org?node_id=554954


in reply to Iterating over code embeded in regex

The snippet bellow shows that the $l inside the embedded code of the regex is a closure.

use Scalar::Util 'refaddr'; for my $l ('a'..'b') { print 'loop variable ', refaddr \$l; $l =~ /(?{ print refaddr(\$l) }) /x; }

Here is the output:

loop variable 135603848 135606104 loop variable 135606092 135606104