use File::Find; my $ct = 0; sub fetcher { if( $_ =~ /\.html?$/) { my $name = $File::Find::name; open ( F, $name ) or die "$!: $name\n"; while( $line = ) { for $i ($line =~ /stuffhere)/gi ) { print "$i\n"; $ct++; } } close F; } } #print "\n\nTotal Count = $ct\n\n"; also tried putting count here and it still prints count after data find( \&fetcher, "/directory" ); print "\n\nTotal Count = $ct\n\n";