A few days ago my Linode VPS ran out of its 360MB of memory during a CPAN installation. CPAN does indeed eat up a lot of RAM, and this is in large part due to the process of building its in-memory database of modules. Fortunately, there is a CPAN module that provides a solution to this problem: CPAN::SQLite.
CPAN::SQLite is a drop-in add-on for CPAN.pm, which can make CPAN store its data in a SQLite database. After installing it, I noticed a reduction from 75MB to 21MB of the amount of RAM used by CPAN while installing a sample module.
Getting CPAN to use CPAN::SQLite is simple:
$ cpan CPAN::SQLite $ perl -MCPAN -e shell cpan> o conf use_sqlite 1 cpan> o conf commit
Once you have done this, you can use the
cpan command normally to install modules, only now it will use significantly less memory while doing so.
Be aware that CPAN::SQLite only works with the most recent releases of CPAN modules. Make sure to read the caveat about this if you think it might affect you. Then enjoy the extra RAM!