MyVariables $MYFOLDER = "/tmp/logs" #Severity Levels $SLEVEL1 = "ERROR"; $SLEVEL2 = "WARN"; #Mycustom Date - this gives 2017-01-04 $datestring = strftime "%Y-%m-%d", localtime; #MyMatches Pattern #$match1 = "^$datestring\s+\d{2}:\d{2}:\d{2},\d{3}\s+-\s+\d{2}:\d{2}:\d{2},\d{3}\s+$SLEVEL1"; sub MyScanLogs { @files = `find $MYFOLDER -name "*.log"`; foreach $file(@files) { open FILE, "$file" or die "Unable to open files"; while() { if ($_ =~ /$match1/) { print "$file $_\n"; } } } } MyScanLogs