in reply to Loading an array with file names

Instead of doing the work yourself, use a module:

use File::Glob 'bsd_glob'; my @files= bsd_glob $dir; print "$_\n" for @files;