perl -pi -e's/foo/bar/g' filename # or, to leave a backup with a .bak extension: perl -pi.bak -e's/foo/bar/g' filename