#build the tree my $root = Tree::DAG_Node->new; $root->attributes({ original=>"permit ip any any", source=>['0.0.0.0/0'], destination=>['0.0.0.0/0'] }); foreach my $node (@node_list){ my $location; $root->walk_down({ callback => sub { my $this_node = shift; if (compare_nodes($node,$this_node)){ $location = $this_node->address; 1; } else{ 0; } } }); $root->address($location)->add_daughter($node) if defined $root->address($location); }