in reply to problem with extra lines when using
So, just s/\r\n/\n/g; before doing anything with the data, and you should be okay.