#!perl -l use strict; use warnings; { # BAD for my $i (0..1) { my $count=0; 'abc'=~/.*(?{$count++})(??{'\\z\\A'})/; print "$i:$count"; } } { # Work around #1, single lexical my $count; for my $i (0..1) { $count=0; 'abc'=~/.*(?{$count++})(??{'\\z\\A'})/; print "$i:$count"; } } { # Work around #2, global explicitly named for my $i (0..1) { local $::count=0; 'abc'=~/.*(?{$::count++})(??{'\\z\\A'})/; print "$i:$::count"; } } { # Work around #3, global our $count; # or use vars qw/$count/; for my $i (0..1) { local $count=0; 'abc'=~/.*(?{$count++})(??{'\\z\\A'})/; print "$i:$count"; } }