my $a = { bill => { '5/27/96' => { 'a.dat' => 1, 'b.txt' => 2, 'c.lsp' => 3 } \ }, jimm => { '6/22/98' => { 'x.prl' => 9, 'y.pyt' => 8, 'z.tcl' => 7 } \ } } ; my @a = Data::Hash::Flatten->this($a, [qw(name date file)]); use Data::Dumper; print Dumper(\@a); $VAR1 = [ { 'hits' => 7, 'date' => '6/22/98', 'name' => 'jimm', 'file' => 'z.tcl' }, { 'hits' => 8, 'date' => '6/22/98', 'name' => 'jimm', 'file' => 'y.pyt' }, { 'hits' => 9, 'date' => '6/22/98', 'name' => 'jimm', 'file' => 'x.prl' }, { 'hits' => 3, 'date' => '5/27/96', 'name' => 'bill', 'file' => 'c.lsp' }, { 'hits' => 2, 'date' => '5/27/96', 'name' => 'bill', 'file' => 'b.txt' }, { 'hits' => 1, 'date' => '5/27/96', 'name' => 'bill', 'file' => 'a.dat' } #### sub this { my (undef, $href, $field, $depth, $flat_rec) = @_; @flattened = () unless defined($depth); if (ref $href) { my @key = keys %$href; # warn "ref $href succeeded. depth: $depth keys: @key, the ref:", Dumper($hre\ f); for my $key_i (0..$#key) { my $key = $key[$key_i]; # warn "KEY: $key"; $flat_rec->{$field->[$depth]} = $key; # warn "(depth $depth) flat_rec->{$field->[$depth]} = $key"; Data::Hash::Flatten->this($href->{$key}, $field, $depth+1, $flat_rec, @fla\ ttened); } } else { $flat_rec->{$field->[$depth]} = $href; # warn "no more refs. we are at bottom. pushing:", Dumper($flat_rec), "here i\ s href:", Dumper($href), "depth $depth"; use Storable qw(dclone); my $new_rec = dclone $flat_rec; push @flattened, $new_rec; } @flattened; }