in reply to Changing user in perl script
Use sudo. It's the perfect tool for exactly this requirement and reimplementing it yourself is hard to do correctly and would likely lead to gaping security holes.