my $cr = chr(0x0d); my $lf = chr(0x0a); my $infile = "test.txt"; open (IN, "<$infile") or die "Couldn't open input file: $!"; my $first_line = ; my ($line_text, $line_ending) = ($first_line =~ /(.*)(\015|\012|\015\012)/); # detect line ending type if ($line_ending eq "$cr$lf") { print "Windows line ending\n"; } elsif ($line_ending eq "$lf") { print "UNIX line ending\n"; } elsif ($line_ending eq "$cr") { print "Mac line ending\n"; } else { print "Unknown line ending\n"; } close (IN);