Just repeating Druxa's answer with an archive.org link since the original is down and paraphrasing below in case that goes down too.
To use perl to replace every instance of M1 with M2, the command for this is -e (execute?). To change something inline, you can use the -i (in place) command. The command looks something like this:
perl -pi.bak -e "s/M1/M2/g" file.txt
The -i.bak means to rename the original files with the .bak extention. In theory -i alone will delete the originals but ActivePerl wouldn't accept this.
The -p tells perl to run the command over every line of standard input (i.e. over every line of the file).
The "s/M1/M2/g" command is a regular expression telling it to substitute M2 for M1 globally. It could be any regular expression. Hint: If the command fails, try adding -w to the command line to generate warnings.
On Windows, the MSDN blog post author warns that quoting with single quotes (') wont work, so you should use double quotes (")
In *nix using a shell interpteter like bash, it interprets some special characters differently using double quotes (") so you should use single quotes (')
The above command will change all instances of M1 to M2 in file.txt. What I wanted to do was to replace it in every file. Simple, I'll just change file.txt to .. Sorry, no dice. ActivePerl doesn't accept this nor does it accept *. Time for some more command-line action. There is a for command that can be utilized at the cmd prompt which fits the bill. Use it like so:
for %i in (*.txt) do perl -pi.bak -e "s/M1/M2/g" "%i"
This command will iterate over all the files (*.txt) and execute the command following the do. You have to quote the trailing %i because filenames might contain spaces. Note that perl regular expressions are capable of much more than simple search and replace. You can use this technique to accomplish anything they can.