$rc = 1; while (defined($nextfile = <$dirName/*cm*.4gl>)) { if ($rc) { $rc = system("grep $field $nextfile 1> /dev/null"); if (!$rc) { print FOUND "$field $nextfile\n"; } } } #### 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; } }