use GraphViz; sub as_graph { my $haystack = shift; my @pitchfork = sort keys %$haystack; my $g = GraphViz->new(); for my $p (@pitchfork) { $g->add_edge($p, $_->{'idref'}) for @{$haystack->{$p}->{'edge'}}; } return $g->as_text; } print as_graph( \%s );