use File::Find; my @topdirs = @ARGV; @ARGV = (); find sub { push @ARGV, $File::Find::name if /\.p[lm]\z/ and -f; }, @topdirs; my $count = 0; @ARGV or die "No files to process!\n"; $count++ while <>; print "Total $count lines\n";