Before making changes to your code, you might want to try forks, a drop-in replacement for threads.pm using fork(). Without the memory problems at the expense of more CPU and latency because sockets are used for communication between threads.
If you are willing to make changes to your code, of course fork() by itself could probably be used as well.