use Graph; my @K = ([1,2], [1,3], [2,3], [2,4], [3,4]); my $g = Graph->new; $g->add_edges( map {@$_} @K ); print $g->vertices;