If you wish the nodes to be stored in a database, then I'd suggest reading (and understanding) Nested Set Trees
. In the common case of insert occasionally, query often, they are far more efficient than the usual adjacency model that people think of.
Unfortunately I don't know of a module that automates generating them in Perl, and I'm not entirely sure what such a module should look like. (Which may be why I don't know of one...) So you'd have to do some reinvention, but at least you'd reinvent a good version.