If your shell tells you that it cannot find “…^M” this means that the file was originally saved on a windows box with different line endings. In order to make that work on linux, use the nifty tool dos2unix.
$ dos2unix mywindowsuploadedperlscript.pl
Voilà 🙂