For what it's worth, take a look at
PerlMoo, now
Mooix. I'm not sure that any of this code would be directly usable in your project, but it incorporates a number of interesting ideas that might help you approach this problem. (Relevant docs are
here and
here.)
Janitored by Arunbear - fixed PerlMoo hyperlink