Reading a directory all at once with an array: Use an array with the readdir command, instead of a scalar variable
#!/usr/bin/perl -w $name = "c:\\"; opendir(DIR, $name) or die "Can't open $name due to $!"; @entries = readdir(DIR); closedir(DIR); # Sort results. @sorted = sort(@entries); foreach $entry (@sorted) { print "$entry\n"; }