use File::Find::Rule; my $cnt = find( file => name => "*.txt", maxdepth => 1, in => "/home/a" ); #### my $cnt = () = glob "/home/a/*.txt"; #### opendir( my $d, "/home/a" ) or die "ack: $!"; my $cnt = grep { -f and /\.txt$/ } readdir $d;