use File::Find; my @dirlist; sub wanted { return unless -d $_; push(@dirlist, $File::Find::name); } find(\&wanted, shift(@ARGV)); # Use @dirlist here