in reply to CPAN.pm programming

I know how to do it from the shell

Just run those shell commands inside system() calls.

Cheers,
Rob