in reply to handling different new line characters

Instead of chomp($line), you could use a regex:

$line =~ s/[\n\r]//g;

This way you're handling both the CR and the LF.

Hope that helped,
-v.

"Perl. There is no substitute."