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

Another way to do it is to skip each file entry unless it matches, ie
foreach $file (@files){ next unless $file =~ /\.dat$/; # other stuff here... }