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


in reply to Irregular expression evaluation

I remember reading something in Mastering Regular Expressions warning against mixing lexicals with (?{}) (though I may be mistaken). Note that this appears to work:

use warnings; use strict; gf (); gf (); sub gf { my $ins1 = '4 A -4 C -4 B 1 D'; our @inserts = (); $ins1 =~ /[\d+-]+(?: \w ([\d+-]+)(?{push @inserts, $1}))*/g; print "\n" . join ' ', @inserts; }