I would write in a sub in perl:
- Get (and read manual) stat from file (permissions, user and group owner)
- If user is the owner, verify r/w permission with S_IRUSR S_IWUSR masks and fix if don't have permission you want
- If user is in group owner (getgrnam), then verify r/w permission with S_IRGRP S_IWGRP masks and fix if don't have permission you want
- If user is not in group owner, then verify r/w permission with S_IROTH S_IWOTH masks, and fix with system and adduser from your S.O.
But probably you should simplify your environment and make a good use of groups and umasks ;)