in reply to how to get total numbers of files in a directory?

There is always another way to do it. ;-)

The following is my method that works on Unix/Linux platforms. It relies on the properties of -F switch of ls
that appends a '/' character after directories, a '*' character after executables, etc.
use strict; use warnings; use Data::Dumper; my @txt_files = map {m!(.*\.txt)[^/]*$!} split /\n/, `ls -F`; # ^txt only ^want non-directories # and throw away the flag print Dumper(\@txt_files); my $num_files = $#txt_files + 1;