in reply to what is $uid and $gid?

The uid is the user id number, gid the group id number. Those are unique numbers associated with the user and group names in /etc/passwd and /etc/groups.

See getpwent and friends for how to deal with those properly in perl.

After Compline,
Zaxo