If you were trying to allocate, or reallocate, an enormous string, array or hash it could have requested a larger memory block than was available from the system. While you have 4 gigs of real memory and 4 gigs of virtual, other processes might have been consuming a large chunk of that.
Alternatively, your system might have a per process memory limit which would might be 2 gigs.
Finally, your OS may be 64 bit, but your Perl may be 32 bit. In that case the maximum amount of memory it can address would be 2 gigs. If you post a copy of perl -V
somewhere we can view we might be able to work that out.