$ cat foo.txt one two three $ perl -wMstrict -pe 's/^t(?!h)/th/; s/(.)\1/$1/g' foo.txt > bar.txt $ cat bar.txt one thwo thre $ perl -wMstrict -pe 's/th/ph/g' -i.bak bar.txt $ cat bar.txt one phwo phre $ cat bar.txt.bak one thwo thre