use strict; use warnings; sub main { my $input = ('D:\Perl\Paul\My_Text.txt'); my $output = 'My_Output.txt'; open(INPUT, $input) or die("$input - Not found \n"); open(OUTPUT, '>'.$output) or die("Can't create $output \n"); while(my $line = ){ if($line =~ s/\bfox\b/dog/ig){ # The \b above are word boundaries # the ig at the end sets "case insensitive" and search globally print OUTPUT $line; } } close(INPUT); close(OUTPUT); } main();