#!/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;