s/frog/toad/g txtfile #### #!/usr/bin/perl -w use strict; # this script will edit itself ReplaceStuff($0,'word','taco'); sub ReplaceStuff{ my ($file,$origword,$newword) = @_; local $^I=""; # set the backup tag to nothing local @ARGV = $file; # make a local @ARGV so we can use <> # go through each line and do the substitution while (<>) { s/$origword/$newword/g; print; # print stuff out } }