push(@Children,$root->child_nodes); # could be push(@Children,$start_node_id); too, any starting point... while(@Children) { $node = shift @Children; print $node,"->"; my $Node = Node->new($node); my $next = $Node->first; while ($next) { print $next,","; my $Child = Node->new($next); push(@Children,$next); $next = $Child->next(); } print "\n"; }