use strict; open(IN,'logfile.txt') or die("cannot open the log file for reading\n"); open(OUT,'>output.txt') or die("cannot open the output file for writing\n");######To create the output file while(){######to read the input file print OUT "$_" if($_=~/\bTWO\b/i); } close(IN); close(OUT);