in reply to filtering file names to be added to an array...maybe.
my @files = grep /\.dat$/, readdir DIR; [download]
while (<*.dat>) { my $file = $_; open(...etc.,etc.); ... } } [download]