sub trav_hash { my $ref = shift; my $type = ref $ref; if( $type eq 'HASH' ) { trav_hash( $ref->{$_} ) for keys %$ref; } elsif ( $type eq 'ARRAY' ) { handle_array( $ref ); } else { die "something weird is in our structure!"; } } sub handle_array { my $arrayref = shift; # do whatever we want with the array here.... } trav_hash( \%data );