in reply to Perl and MySQL privileges
There is a file in your mysql/bin file called mysql_setpermission that is a Perl script that has similar functionality to what you are attempting to do. You may want to study that code for ideas