Here is an example of java backed webcript process:
You can pass the list of users and GroupId (e.g. GROUP_XYZGROUP) to the webscript and iterate each userId and get the person NodeRef using PersonService (org.alfresco.service.cmr.security.PersonService):
Once you get groupNodeRef, call below given method (sample method, you can create your own if needed) and pass the group Noderef and person nodeRef to it. You would need NodeService and AuthorityService for this call.
Definitely can do this with code as others have suggested, but I thought I'd give you some additional food for thought...
You might consider using an LDAP directory to manage your users and groups. Then you can do such things easily using the directory management tools associated with whatever directory you are using, and Alfresco will happily sync everything over.
The side-benefit, of course, is that other applications in your enterprise can also benefit from having a centralized directory. Plus, it is a lot easier to delegate administration of users and groups using an LDAP directory than it is with Alfresco natively.