for i in file1.txt file2.txt file3.txt do mv $i $i.bak perl -plwe 's/foo/bar/g' < $i.bak > $i done