in reply to memory leak

How do you debug a script that - you've been told - is causing memory leaks?
Because of Perl's reference-count based memory management, circular references will cause memory leaks. To help you find them, see: For a concrete example of dealing with circular references in Perl, see Eliminate circular reference memory leak using weaken.

Some CPAN modules that might prove useful:

Tracking down memory leaks at the C level can be done with a tool like valgrind, as discussed in Re: Valgrind, Perl, and banishing leaks.

As to when the memory is actually released back to the OS, see the answers to this question.