in reply to Unable to remove ^M in the file

^M is the "carriage return" character, represented by "\r". It is added before the newline character ("\n") typically on Microsoft Windows.

There are several ways around it. Make sure you save the file as a UNIX file format, not Windows (sometimes called "DOS").
You can remove it in Perl with :
$lines[$i] =~ s/\r//g;

or:
local $/ = "\r\n"; chomp @lines;
but you will have to add the "\n" when writing the line out.

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.