#!/usr/bin/perl -w use strict; use File::Util; my $hf = File::Util->new(); my $path = '/'; my @Folders; foreach ($hf->list_dir($path,'--dirs-only')) { my @tmp = $_; push @Folders, \@tmp; # the outer array ref } foreach (@Folders) { my $lf = File::Util->new(); my @tmp = $lf->list_dir($path.$_->[0],'--dirs-only'); $_->[1] = \@tmp; # inner array ref } # verify: foreach (@Folders) { print $_->[0]."\n"; foreach my $sub (@{$_->[1]}) { print "\t$sub\n"; } }