# $insert_values = { ...hashref of keys and values... }; # # Break up the hash into separate pieces for columns # and values to use in the sql insert statement. # my @keylist; push @keylist, [ $_, $insert_values->{$_} ] for keys %$insert_values; my ( @columns, @values ); for ( @keylist ) { push @columns, $_->[0]; push @values, $_->[1]; } # # Construct our query based on the lists of columns and # their values. # my $sql = "INSERT INTO table_foo (\n" . join( ", ", @columns ) . "\n) VALUES (\n" . join( ", ", @values ) . "\n)\n";