What you are describing is mathematically a directed graph and can be represented in Perl as a Graph object using the module
Graph. That module also has a number of methods for processing graphs. For instance, one could do a topological sort to establish the hierarchy of dependencies.
use Graph::Directed;
my $g = Graph::Directed->new; # A directed graph.
$g->add_edge(...);
$g->add_vertex(...);
$g->vertices(...)
$g->edges(...)
my @ts = $g->topological_sort;
For modules in particular, check out Module::Dependency for useful methods.