perl -pe"s/foo/bar/g" file.txt
Or in-place:
perl -i -pe's/foo/bar/g' file.txt
On Windows:
perl -i.bak -pe"s/foo/bar/g" file.txt