Check the man pages for the Unix 'chown' command. If you specify a user:group, the GID of the file is set to 'group' (the part that follows the colon).
If you want to do recursion, you should probably look into File::Find, which does all of that for you.