In order of easiest/cheapest (on developer costs) to most difficult ...
Check your ulimit. If you have a limit on memory from that, then you'll get an out of memory error when you reach it. I had this problem - 64MB wasn't enough, so I just told the sysadmins that I needed unlimited memory, and that problem went away.
Buy more RAM/increase swap space. If you still don't have enough memory after the above, then maybe it's because there's no more memory to have. My current home computer has 4GB of RAM and 8GB of swap specifically because of this. Of course, RAM is way faster than swap.
Try upgrading to 64-bit. That means a 64-bit processor as well as 64-bit OS and 64-bit perl. With sufficient memory. If approximately 3.5GB isn't enough memory to access, then 64-bit will allow you to access anything you can throw at it.
Try using a file-system-backed tied data structure. Since I don't use this, nor do I know what data structures you're using, I can't really tell you which one. But the basic idea is to throw all your intermediate results to disk, and read them back in as you need them. A tied structure, such as DBM or something, can radically simplify this. This allows you to use your hard disk as if it were RAM, without actually hitting the limits of your ulimit or CPU or physical RAM/swap.