local $/ = "\r\n"; while () { chomp $_; print STDERR "'$_'\n"; } #### while () { s/\r[\n]*/\n/gm; # now, an \r (Mac) or \r\n (Win) becomes \n (UNIX) chomp $_; print STDERR "'$_'\n"; } #### s/\r[\n]*//gm; #### open FH, '<', $file or die "Can't read '$file': $!"; # find out what kind of line endings we have my $buffer; local $/ = undef; while ( read( FH, $buffer, 1024 ) ) { if ( $buffer=~m/(\r[\n]*)/s ) { $/ = $1; # set the input separator to what we found last; # stop trying to find the separator } } close FH; # now reopen the FH and read line by line open FH, '<', $file or die "Can't read '$file': $!"; while () { chomp; print STDERR "'$_'\n"; } close FH;