sub depth { my $array = shift; my $count = 0; while (ref $array eq 'ARRAY') { $array = ${$array}[0]; ++$count; } return $count; }