... while (my $file = readdir(DIR)) { if ($file) { $file_count++; } } ...