$flat = { 0 => { 'parents' => undef, 'children' => [2,3,5] }, 2 => { 'parents' => [0], 'children' => [20,23] }, 3 => { 'parents' => [0], 'children' => [23,30,35] }, 5 => { 'parents' => [0], 'children' => [35,50] }, 20 => { 'parents' => [2], 'children' => [200,223] }, 23 => { 'parents' => [2,3], 'children' => [223,230,233] }, 30 => { 'parents' => [3], 'children' => [233,300,335] }, 35 => { 'parents' => [3,5], 'children' => [335,350] }, 50 => { 'parents' => [5], 'children' => [350,500] }, 200 => { 'parents' => [20], 'children' => undef }, 223 => { 'parents' => [20,23], 'children' => undef }, 230 => { 'parents' => [23], 'children' => undef }, 233 => { 'parents' => [23,30], 'children' => undef }, 300 => { 'parents' => [30], 'children' => undef }, 335 => { 'parents' => [30,35], 'children' => undef }, 350 => { 'parents' => [35,50], 'children' => undef }, 500 => { 'parents' => [50], 'children' => undef }, }; #### $child = 2; $gks = @{$flat->{$flat->{$child}{children}[0]}{children}}; print join( ', ', @$gks ), "\n";