in reply to how to switch user
You can either change the $< and $> builtin variables (real user id and effective user id respectively) to the appropriate numberic user ID (bearing in mind you have to have superuser privileges to do so) or use POSIX::setuid to change both at once (again you have to have the appropriate privileges to do so). Bear in mind that this is likely to be a one way operation - once you have become a less privileged user you will not be able to be switch back to the more privileged one. If you do need to switch back it might be appropriate to fork and change the user id in the child process.
/J\
|
|---|