open my $file, $firstTextFile or die "Unable to open"! while(<$file>){ if($_ =~ /hue/){ $_ =~ s/hue/someword/g; // How do i now write to a text file all the previous things in the first text file except for the word hue being replaced with the word someword in the new text file? } }