You've discovered the general principle yourself -- while clobbers $_, while for implicitly localizes it. The most common suggestion is to use a lexical loop variable in your for loop:
for my $b (@bb) { while (<STDIN>) { print "while=$_\n"; last; } print "forwhile=$b\n"; }
In reply to Re: While but not for clobbers $_
by chromatic
in thread While but not for clobbers $_
by tenya
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |