my @files=grep {$_ ne '.' && $_ ne '..'}
@files=readdir(DIR);
Not directly related to your question, but I've seen this construct a couple of times now in code you posted, so I
thought it's maybe worth commenting on... before it becomes a habit :)
The 'normal' way to write this would be
my @files=grep {$_ ne '.' && $_ ne '..'} readdir(DIR);
No need to assign the list of files to an intermediate array
— which is also a different (i.e. package) variable from the
first lexical my @files, BTW.
Has anyone ever suggested to try use strict? ;)