use Graph::Directed; my $graph = Graph::Directed->new; # Building the graph. In this example, edges are directed from a job to a dependency. while (my $line = $file->getline) { my ($job, @deps) = split(/,/, $line); foreach my $dep (@deps) { # adds both $job and $dep as nodes in the graph if they don't exist already $graph->add_edge($job, $dep); } } # What does job FOO require? say "FOO requires $_" foreach $graph->all_successors('FOO'); # Who requires FOO? say "FOO is required by $_" foreach $graph->all_predecessors('FOO'); # Jobs that do not have prerequisites. say "$_ can be executed right now!" foreach $graph->sink_vertices; # Somebody messed up here: say "A job requires itself!" if $graph->has_a_cycle;