in reply to Bad file descriptor error

Here you are matching the regular expression using 'm' is not enclosed properly. Please correct it as follows if ($file =~ m/^\.{1,2}$/) # Ignore . and ..