for my $file (@search_files) { my $next_file = 0; open(SF, "<", "../templates/$file") or die("Cant open Template to search in: $!"); while (my $line = ) { my @keywords = split (/ /, $keyword); for my $word (@keywords) { if ($line =~ /$word/i) { push(@matches, $file); $next_file = 1; last; } } last if $next_file; } close SF; } return @matches; }