my @cols = ('field1','field2','field3'); while ( my $row = $sth->fetchrow_arrayref ) { # create a hash ref to assign values to cols my $tmp = {}; @$tmp{@cols} = @$row; push @xml_array, $tmp; } # Access fields like so... print $xml_array[0]->{field1},"\n";