Successfully removed 0d0a, but have a question

Hello,
I had a file which had 0d0a at the end and was giving me some problems, but I have managed to get rid of it using the following code.

My only question however is, how do I change s/\r\n\z//; when I'm using the while loop as while ($line = <FILE>). I understand that I will have to perform s/\r\n\z//; on the $line, but I'm not able to.

Also note that you can change the input record separator, contained in $/. That's the variable perl is using when reading the file, and which by default is "\n" on Linux, and "\r\n" on Windows. If you are reading a Windows file on a *nix machine, that's a good time to make the adjustment:

Code:

{
local $/ = "\r\n";
while (<FILE>) {
chomp;
print;
}
}

The while loop will separate the lines at whatever record separator you want to use, and then chomp removes the record separator ("\r\n" in this case) from the end of $_.