%HoA =( ##id =>["term","parent_id","left_id", "right_id"] 1 => ["Body Regions","","",""], 2 => ["Extremities","1","",""], 3 => ["Arm","2","",""], 4 => ["Elbow","2","",""], 5 => ["Hand","2","",""], 6 => ["Fingers","5","",""], 7 => ["Thumbs","6","",""] ); #### my %HoA; my $k; my $root = 1; my $ctr =1; for $k (sort keys %HoA){ walktree($root) unless $k eq""; } sub walktree{ my $id = shift; $HoA{$k}[2]=$ctr++ if $id = $k; ##The walktree recursive sub below enters an eternal loop ##and doesn't execute properly. When I tried to push the ##children elements to a temporary array, it worked just ##fine. Would it be the $id??? walktree($id) if $id =$HoA{$k}[1] ; $HoA{$k}[3]=$ctr++; local $" = "|"; print "$k = @{$HoA{$k}}\n"; }