in reply to How to extract the filenames in an array

use strict; my $dirpath = '/usr/C'; opendir(my $dir, $dirpath) or die "Error when using opendir $!"; my @namearr = grep {-f "$dirpath/$_"} readdir($dir); # get only files +and skip directories

It is usually more efficient to use Perl's own internal functions rather than shelling out to an external command or program.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James