my @KEYWORDS = qw(hello there you gurus); # create the regex my $string = ''; foreach (@KEYWORDS){ $string .= "$_||"; } $string =~ s/\|\|$//; # open the log file open(LOGFILE,$logfilename)||die"Cannot open $logfilename\n$!\n" # let's go through the files.... foreach (@files) { $filename = $_; open(FILE,$filename)||die"Cannot open $filename\n$!\n"; #check if a keyword is in the line while(){ if (/$string/i){ print LOGFILE "Keyword found in $filename\n"; } } }