my $first_line = (<$IN>); my $endofline = $first_line =~ /\r\n$/ ? "\r\n" : "\n"; # process first line ... while (my $line = <$IN>) { # ... }