What's the error? As for not complaining about root, perldoc -f getpwnam mentions that the return value is the uid corresponding to the name, or undef if the username does not exist. Root is uid 0, so you really need to check the definedness of the return value: