in reply to filtering file names to be added to an array...maybe.

Change the line

@files = readdir(DIR);

to

my @files = grep( /\.dat$/, readdir(DIR));

grep in this case will return all the elements of the list returned by readdir that end with a ".dat".

BTW:Athough this has nothing to do with your question, I would recommend always adding use strict; to the top of your scripts. strict will catch a lot of tricky errors.

----
Coyote