$ ls | grep FOO | wc -l
####
#!/usr/bin/perl -w
use strict;
use warnings;
use diagnostics;
my $path="/some/where/over/the/rainbow";
opendir(DIR,$path) or die "$!";
my @list=readdir(DIR);
closedir(DIR);
my @collect=grep /FOO/,@list;
my $count = $#collect + 1;
printf "total count = %d\n",$count;
####
$ grep FOO * | wc -l
####
#!/usr/bin/perl -w
use strict;
use warnings;
use diagnostics;
my $path="/some/where/over/the/rainbow";
open (DIR,$path) or die "$!";
my @file_list=readdir(DIR);
closedir(DIR);
my $count = 0;
foreach my $file(@file_list){
open(FIN,"< $file") or die "$file: $!";
my @slurp=;
close(FIN);
my @collect=grep /FOO/,@slurp;
$count += ($#collect + 1);
}
printf "My total count was: %d\n",$count;