in reply to Action at a great distance

How is any of this any surprise? It's just Yet Another Imprudent Use Of $_. We have seen so many cases like these. A common trap seems to be calling a function with a while(<>){} from inside a map or such. There are examples up the wazoo about this kind of trap.

Always localize $_ before you clobber it!!

It's that simple. Don't act all surprised when you get bitten in the rear if you don't. The only time you can skip this step is foreach, map, and grep, because they alias, rather than assign, to $_. Other than those, localize without even thinking. Make it a habit. Make it a habit. Really, make it a habit.

Makeshifts last the longest.