open HANDLE, $file or die "Couldn't open $file: $!\n"; print "Please Enter a word from $file: "; chomp($word_1 = ); print "Please Enter a Word to Replace, $word_1, with: "; chomp($word_2 = ); # Read the whole thing in. undef $/; $x = ; close HANDLE; # Re-open for writing, clobbering the file. open HANDLE, ">$file"; # Change every instance $x =~ s/$word_1/$word_2/g; # To prevent changing substrings, it would almost # certainly be better to use: # $x =~ s/\b$word_1\b/$word_2/g; # But it's your call.... print HANDLE $x;