Graph::BFS (breadth-first search) looks like exactly what you need. Tables are vertices, foreign keys are edges (unfortunately, at a quick glance it does not look like you can name edges). Look at its superclass Graph::Traversal for the documentation, which is sparse even there. You'll need to create the graph using Graph::Undirected (again, look at the documentation in the superclass Graph::Base). Here's the
package.