in reply to Running a perl script with root, changing to another user and then back to root?
You could just fork and setuid in the child. Then you communicate with the the child via some IPC, e.g. a set of pipes.