open IN, '<', $filename or die ("Can't open $filename: $!"); sysseek IN, -5, 2; my $last_five; sysread IN, $last_five, 5; ## find out what the EOL chars are and set $\ to match $/ = $1 if $last_five =~ m/(\r{0,1}\n)$/s; sysseek IN,0,0; while () { chomp; # now process stuff # }