for my $nextfile (glob File::Spec->catfile($dirName, '*cm*.4gl')) { $rc = system("grep $field $nextfile 1> /dev/null"); if (!$rc) { print FOUND "$field $nextfile\n"; last; } }