my $sql= new SQL::Abstract( array_datatypes => 1 ); my $required = { a => [1, 3, 5], b => [2, 4, 6],}; my($stmt, @bind)= $sql->insert( testtable => $required ); #### stmt: "INSERT INTO testtable ( a, b) VALUES ( ?, ? )" @bind: ( [ 1, 3, 5 ], [ 2, 4, 6 ] ); #### my $data = [ {a => 1, b => 2}, {a => 3, b => 4}, {a => 5, b => 6}, ]; #### # %columns will become the hash of arrays my %columns; # Foreach row of data collect its keys and create an empty array in %columns $columns{$_} //= [] foreach map { keys %$_ } @$data; # Then, for each row foreach my $row ( @$data ) { # push the value foreach column push @{$columns{$_}}, $row->{$_} foreach keys %columns; }