I showed the sed way to search for a pattern in a file, replace every occurrence of the pattern with something, and write all the changes back to the same file. I am, now, going to show you the Perl one-liner way of doing it.
$ perl -p -i -e 's/pattern/replace/g' file
Or, if you wish to backup the file first, and then make changes, here is the altered form:
# perl -p -i.bak -e 's/pattern/replace/g' file