use strict; use warnings; my %hash = ( accesslevels => { function => { func1 => { content => 'val1' }, default => { content => 'val2' } } } ); sub flatten { my $hash = shift; while ( my ( $k, $v ) = each %$hash ) { next unless ref $v eq 'HASH'; flatten( $v ); exists $v->{ $_ } and $hash->{ $k } = $v->{ $_ } for qw( function content ) } } use Dumpvalue; flatten( \%hash ); print Dumpvalue->new->dumpValue( \%hash ); __END__ 'accesslevels' => HASH(0x814cad4) 'default' => 'val2' 'func1' => 'val1'