use warnings; use strict; my $struct = [ { 1 => 'a', 2 => 'b', }, [ 1, 2, 3, ], { 3 => 'c', 4 => 'd', }, ]; thing($struct); sub thing { my ($aref) = @_; for my $elem (@$aref){ if (ref $elem eq 'ARRAY'){ print "array:\n"; print "$_\n" for @$elem; } elsif (ref $elem eq 'HASH'){ print "hash:\n"; print "$_ => $elem->{$_}\n" for keys %$elem; } else { die "element is not an allowed ref\n"; } } }