in reply to memory usage/leaks

The biggest thing you can do is start using strict.pm to catch when you use globals, and use lexical variables (declared with my) everywhere. This should result in having all uses of data tightly scoped, giving Perl a clean point to drop it.

After that look for an ever increasing arrays or self-referential data structures. There are also some internal Perl leaks (eg anonymous functions are not currently freed.) A useful tool for tracking down that kind of thing is Devel::Leak.

When I have had to track this kind of thing down in the past, I have done things like override bless (see perlsub to learn how to do this) so that I kept track of caller information about object assignment, then I had a UNIVERSAL::DESTROY method that would catch when the objects went away. This gave me pretty complete information on where things that weren't getting freed were being assigned. (And with this idea you can fine-tune things to only get the packages you are interested in.)

That is a little tricky though. Most of the time you will get it just by being strict.pm and making all of your variables tightly scoped.