Those ^Ms are "\015"s, which is "\r" practically everywhere. Note
that line-oriented scripts "almost" work on CRLF text files on Unix
because CRLF has a trailing "\n" by chance. I think this is
unfortunate because instead of just breaking your program there's
the annoying situation where you still read lines but there's
something spurious at the end you don't completely understand.
If the script is line-oriented, to read CRLF text files under Unix it
is enough to set
$/ = "\r\n";
and chomp each line as usual.
If you want to preserve newlines instead of chomping then s/\r\n/\n/