in reply to lexical weirdness(?)

*Cough* Weird one..
Does this behaviour still occur if you declare my $line on it's own on the second loop?
If not, a wild stab in the dark would be that you're somehow forcing the $line to stay in scope by using it along with the if and substitute on the global variable $data, like a closure.

Malk
(This is a VERY wild stab in the dark)
*I lost my .sig. Do you have a spare?*