Actually, I don't think that works. The reasoning is that since $_ is local'ed inside foreach loops, any loop variable should be. This is supposedly in support of the principle of "least surprises". Anyway, with 5.05003 I get:
> perl -lwe '$x=$y=0; foreach $x (0..9) { ++$y } print "$x, $y"'
0, 10
> perl -lwe 'my($x,$y)=(0,0); foreach $x (0..9) { ++$y } print "$x, $y
+"'
0, 10
> perl -lwe '$y=0; foreach $x (0..9) { ++$y } print ! defined $x,", $y
+"'
1, 10
> perl -lwe 'my $y=0; foreach my $x (0..9) { ++$y } print ! defined $x
+,", $y"'
Name "main::x" used only once: possible typo at -e line 1.
1, 10
>
p |