in reply to Remove ^M using script
Read the error message.
perl -pi 's/\r\n/\n/' $a [download]
is not the same as
perl -pi -e 's/\r\n/\n/' filename [download]