my $t = Graph::Traversal::DFS->new($g, pre => sub {push @pre,$_[0]}, post => sub { print join(',',@pre),"\n" if($g->degree($_[0]) == 1 && $_[0] ne $startnode); pop @pre;}, next_alphabetic=>1, # if you want output order to be deterministic, otherwise will display paths in arbitrary order start => $startnode);