in reply to Is this a logic bug or a perl bug?

In addition to the other comment, I would avoid using a file handle called 'DATA' just so you don't confuse people. DATA is the name of the filehandle to get stuff from the __DATA__ area of your script file.