$isok = 1; for $logname("logfile1", "logfile2", "logfile3") { open FH, $logname ...; @isthisfileok=(0)x 6; while() { $isthisfileok[$1]++ if /^snapshot([1-6])/; # last if /^snapshot([7-9]|\d{2,})/; # are snapshots sorted numerically? then you don't have to search whole file if found snapshot7 or other } close FH; $somesnapshotnotfound = grep $_ == 0, @isthisfileok; $isok = 0 if !$somesnapshotnotfound; last if !$isok; # don't scan another file if already not ok } print "everything ok" if $isok;