my $root = 'd:/perl/'; my ( @dirs, @fails, @files); @dirs = ( $root ); for my $dir ( @dirs ) { opendir DIR, $dir or die $!;#do { push @fails, $dir; next }; while ( $_ = readdir DIR ) { next if -s "$dir/$_"; do{ push @dirs, "$dir/$_"; next } if -d "$dir/$_" and not m/^\.\.?$/; do{ push @files, "$dir/$_"; next } if -f "$dir/$_"; } } print "$_\n" for @dirs;