use File::Find; my $category; for my $file (@file_list) { my $file_path = dirname($file); # better make sure this is working! my $count = CountFiles($file_path); if ($count < 200) { $category = "paper"; } else { $category = "collection" } } # Count all files contained inside a directory, recursively sub CountFiles { my $dir = shift; my $count = 0; find( sub { if (-f) { # only count regular files ++$count; } }, $dir); return $count; }