in reply to switch user

Have you looked through the sudo cpan module? Obviously, sudo access needs to be set up for the particular user the perl script is run as. Assuming that, it should do exactly what you are looking for.