while(my $line = ) { $line=~s/word1/word2/; print OUTHANDLE $line; }