The GraphViz module is what you want. It allows you do do everything that Dot does (define and label nodes and edges) but from within Perl. It should be a simple matter of getting your data via DBI and then going through it to call add_node and add_edge.