sub print_thing { print join("\n", _thing_helper(shift)),"\n"; } sub _thing_helper { # return a list of strings representing the thing we're given my $thing = shift; # ok, what is it? if (ref $thing eq "ARRAY") { return "array [", # Turn each thing in the list into a string map( { _thing_helper($_) } @$thing ), "]"; } elsif (ref $thing eq "HASH") { return "hash {", # Turn each thing in the array into a string map( { "$_ =>" . _thing_helper($$thing{$_}) } keys %$thing), "}"; else { # A good solution would also do something with objects... return "$thing"; } }