while (<$fh>) { # If the file contained lines ending with CRLF, $_ ends with CRLF # If the file contained lines ending with LF, $_ ends with LF s/\r?\n\z//; # Removes CRLF or LF }