in reply to Process file regardless of the platform it was created on

There are conditions on my current macosx where an app will save a "plain text" version of a file using just CR for line termination, even though the OS is really a flavor of unix, and perl's default $/ on macosx is LF. (I can only wonder how much longer this CR silliness will go on.) I know that CRLF comes from a variety of web apps as well as from ms-win systems. Alas, $/ has to be a literal string -- you can't use a regex as the input record separator.

If you never encounter any really huge CR-format files, you might want something like this:

while (<>) { my @lines; if ( /\n$/ ) { tr/\r\n//d; @lines = ( $_ ); } else { @lines = split /\r/; } for my $line ( @lines ) { # do stuff with each line of text } }
Either that or else you just use slurp mode in all cases, and split into lines (using  /[\r\n]+/) if you really need to do that.

If you have to worry about getting really huge files in any of the three possible formats, you'll want to diagnose each file first -- at least, check the file size first, and if it's really big, read just enough (e.g. read FH, $_, 2048;), to figure out what the line termination is, set $/ accordingly, then rewind it (seek FH,0,0;) to read the whole thing as it was intended to be read.