$/ = "\r\n"; while (<>) { if (s/^\r//) { $l .= $_; $l =~ s/\r\r//g; next; } else { print $l; $l = $_; } } print $l;