my %xml_hash = ( rootnode => [] ); # top XML node has an empty array_ref as value while ( my $row = $sth->fetchrow_hashref ) { push @{$xml_hash{rootnode}}, $row; } print $xmlobj->XMLout( \%xml_hash );