use warnings; use strict; use Tree::Simple; my $tree = Tree::Simple->new("0", Tree::Simple->ROOT); while() { chomp; my ($child, $parent) = split ":"; my $sub_tree = Tree::Simple->new("$parent", $tree); $sub_tree->addChild(Tree::Simple->new("$child")); $tree->DESTROY(); } $tree->traverse(sub { my ($_tree) = @_; print (("\t" x $_tree->getDepth()), $_tree->getNodeValue(), "\n"); }); __DATA__ apple:fruit granny smith:apple rotten granny smith:granny smith orange:fruit