use strict; use warnings; use Data::Dumper; # Prototype defined to avoid 'function not defined' warnings # on compilation. sub unpack_row{ my $hash = shift; my @row = @_; if(ref($hash) eq 'HASH'){ my $header = $hash->{'header'}; my @results = ( ); while(my ($key, $value) = each(%$hash)){ # Save the results the way you need them... push @results, unpack_row($value, (@row, $key)); } return (@results); # ... or whatever you return } else { print Dumper((@row, $hash)); return (@row, $hash); } } my $hash = {}; $hash->{'foo'}->{'bar'}->{'bat'} = 5; print unpack_row($hash, ());