I'm unaware of a native Perl function that will reset the MySQL root password, but there are many nooks and crannies of the language that I'm still discovering. :-)
You can do it using SQL to update the mysql database user table which is where the password lives. You can also use GRANT. You can also use mysqladmin as a system call to change passwords. Other than that it can't be done ;-) It is all in the extensive mysql docs for those inclined to RTM.
Recovering from a lost root password is discussed below