The following is an old example I wrote that does what you are asking. It would be better to change it to call the api calls directly instead of make a GET request to localhost though.
Code:
#!/usr/bin/perl
use LWP::UserAgent;
if ($#ARGV > 1) {
open(AHASH, "/root/.accesshash");
my @access = <AHASH> ;
close AHASH;
my $hash = join("\n", @access);
$hash =~ s/\n//g;
my $dbuser = "cpanel1";
my $dbpass = "somesecurepass";
my $dbname = "cpanel1";
my %OPTS = @ARGV;
my $user = $OPTS{'user'};
my $auth = "WHM root:" . $hash;
my $ua = LWP::UserAgent->new;
#add database
my $request = HTTP::Request->new( GET => "http://localhost:2086/xml-api/cpanel?user=$user&cpanel_xmlapi_module=Mysql&cpanel_xmlapi_func=adddb&cpanel_xmlapi_apiversion=1&arg-0=$dbname" );
$request->header( Authorization => $auth );
my $response = $ua->request($request);
#add database user
$request = HTTP::Request->new( GET => "http://localhost:2086/xml-api/cpanel?user=$user&cpanel_xmlapi_module=Mysql&cpanel_xmlapi_func=adduser&cpanel_xmlapi_apiversion=1&arg-0=$dbuser&arg-1=$dbpass" );
$request->header( Authorization => $auth );
$response = $ua->request($request);
#add user to database
$request = HTTP::Request->new( GET => "http://localhost:2086/xml-api/cpanel?user=$user&cpanel_xmlapi_module=Mysql&cpanel_xmlapi_func=adduserdb&cpanel_xmlapi_apiversion=1&arg-0=$user\_$dbname&arg-1=$user\_$dbuser&arg-2=ALL" );
$request->header( Authorization => $auth );
$response = $ua->request($request);
}