http://www.perlmonks.org?node_id=2586
Description: If you transfer text files back and forth between Windows and Unix, you may notice a strange ^M character showing up here and there. There's an easy way to get rid of it, though. Try the first one liner. In a Unix environment, you can remove the \r character (as EOL for Unix is \n) with the second one liner.
perl -pi -e 'tr/\cM//d;'  <filename>

perl -pi -e 'tr/\r//d';  <filename>