Well, you're using $_ as the loop variable in two nested loops. That's bound to cause trouble. Use an explicit loop variable in at least one of the loops and the problem should go away.
Also, why the nested loop in the first place? Normally it makes no sense to read everything from DATA more than once.
holli
You can lead your users to water, but alas, you cannot drown them.
Yes, __DATA__ is a bit of a red herring, since originally it was multiple reads of an external text file.
That aside, thanks all for the explanation (and the fix). I must admit I thought I'd tried the solution already, but obviously not... also, I thought it was okay to use multiple nested instances of $_, and that each was local to its block, but clearly not...