use strict; use Graph::Undirected; use Data::Dumper; # Suppose list1 consists of the # edges to add. Lowercase is first # list, uppercase is second list. # a to A, B, C # b to C, D my @list1 = ( [ qw(a A) ], [ qw(a B) ], [ qw(a C) ], [ qw(b C) ], [ qw(b D) ]); my $g = new Graph::Undirected; foreach my $ids (@list1){ $g->add_path(@$ids); } $Data::Dumper::Indent = 1; print Data::Dumper->Dump([\$g], [qw(*g)]);