Without a backup copy (not supported on Windows)
perl -i -pe's/foo/bar/g' file.txt
With a backup copy file.txt.bak
perl -i.bak -pe's/foo/bar/g' file.txt
With a backup copy old_file.txt.orig
in the backup
subdirectory (provided the latter exists):
perl -i'backup/old_*.orig' -pe's/foo/bar/g' file.txt