my $count = 0; foreach (@keywords) { if( ($_ eq "database.txt") || ($_ eq "keywords_database.txt") ) { print "Found $_\n"; $count++; last if($count == 2); } } if($count != 2) { print "At least one database is missing.\n"; GenerateTestFileList(); }