The backstory is that the original script didn't have the "my" lines in it - I added them because with strict on, perl complained. I somehow dropped them inside the while loop without thinking about the consequences of redefining the variables in every iteration of the loop.