http://qs321.pair.com?node_id=104821


in reply to problem with extra lines when using

I suspect that you have "\r\n" line-endings, and somewhere along the way the \r is turning into an extra newline.

So, just s/\r\n/\n/g; before doing anything with the data, and you should be okay.