in reply to reg exp

if ($file=~/[a-zA-Z0-9_]\.dat/){

The [a-zA-Z0-9_] can be shortened to \w. Guessing from your error message and some of your variable names, English isn't your first language, and I bet your system will allow characters in filenames that aren't on an English keyboard, in which case the regex you have above won't match all valid filenames (in fact, it won't even on an English-native system, since almost everyone these days allows spaces in filenames). \w will probably respect your locale, though I haven't checked it.

Actually, you can get around all of this by using -e instead of that regex, which will check for the existance of a file. So that if statement becomes:

if( -e $file ) {

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

:(){ :|:&};:

Note: All code is untested, unless otherwise stated