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


in reply to Quick and portable way to determine line-ending string?

Most (all?) platforms will use one or more of 0x0a and 0x0d characters as the newline, so something like:
sub seperator { my $cr = chr(0x0d); my $lf = chr(0x0a); if($_[0] =~ /([$cr$lf]+)/o) { return $1; } #unable to find seperator, handle error here. }
This assumes that the file will not contain an 0x0a or 0x0d unless it is used as part of the newline, which should be true of a textfile.

Update If the first occurance of the newline is multiple newlines (for example "\n\n\nThree lines before me\n") then all of them will match and it will not return the correct line seperator. Best to just check for $cr$lf, $lf$cr, $cr, and $lf individually.