use File::Find; # set up closure here my @dirlist; sub wanted { return unless -d $_; push(@dirlist,$File::Find::name); } # call the sub to fill @dirlist find(\&wanted, shift(@ARGV)); # use results here print "$_\n" for @dirlist;