in reply to While but not for clobbers $_

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"; }