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