c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $ComponentData = { 'key_A' => { '6.0' => [ { 'FILENAME' => 'filename', 'VERSION' => 'version', ooo => 'xxx', }, ], }, }; dd $ComponentData; ;; print highest_multi_element($ComponentData)->{FILENAME}; print highest_multi_element($ComponentData)->{ooo}; my $coderef = sub { return { ooo => 'yyy' }; }; print highest_multi_element($coderef)->{ooo}; ;; sub highest_multi_element { my $dataref = shift; ;; if (ref $dataref eq 'HASH') { my ($single, $val, $multi) = %$dataref; die 'empty hash' unless defined $single; return defined $multi ? $dataref : highest_multi_element($val); } elsif (ref $dataref eq 'ARRAY') { my $items = @$dataref; die 'empty array' unless $items; return $items > 1 ? $dataref : highest_multi_element($dataref->[0]); } else { die qq{not hash/array ref: $dataref}; } } " { key_A => { "6.0" => [ { FILENAME => "filename", ooo => "xxx", VERSION => "version" }, ], }, } filename xxx not hash/array ref: CODE(0x66a6bc) at -e line 1.