#!/usr/bin/env perl -l use strict; use warnings; use autodie; use Graph::Undirected; my $graph = Graph::Undirected::->new(); open my $input_fh, '<', './pm_graph_undirected.txt'; while (<$input_fh>) { my ($x, $y) = /^\w+[#]([^<]+)\s+<=>\s+(.*)$/; $graph = $graph->add_edge(split /,/) for glob join ',' => map { '{' . join(',' => split /[+ ]+/ => $_) . '}' } ($x, $y); } print $graph;