Out of Memory error when free memory size is large

I was running a program and it stopped and showed "Out of Memory!". at that time, the RAM used by this process is around 4G and the free memory size of the machine is around 30G. Does anybody know what maybe the reason? this program is written with Perl. the OS of the machine is Solaris U8. And I did not set the max memory for this program using ulimit.

BTW, if you think I posted the question to the wrong place please let me know which forum I should post it to. Thanks.

Is the OS 32-bit or 64-bit? In a 32-bit program, the per-process maximum memory limit is 4GB no matter how much more the OS may have available.