in reply to swaping words
open (HANDLE, "$file"); open (HANDLE, ">>$file"); [download]
Why not use s/$word_1/$word_2/i or similar?