in reply to Variable being clobbered by a seemingly unrelated while loop
There is, unfortunately, a lot of “old code” just like that. (Sometimes with commented-out use strict; use warnings; statements, with comments like, “get rid of warnings.”) All you can really do is to carefully fix the code to use local variables (e.g. foreach (my $foo = ...) and so on), and clean-up the other code that is “too clever.” It is very messy work because you really can’t be sure that the code in question actually worked before. Only that it “seemed to.” It was never rigorously tested. You can waste a lot of time with this stuff.