my %sql_data = ( name => $name, address => $address, # and so on ); my $sql = q/INSERT INTO sponsor (/ . join(',', keys %sql_data) . q/) VALUES (/ . join(',', ('?') x keys %sql_data) . q/)/; my $sth = $dbh->prepare($sql) or die $dbh->errstr; # values() is guarenteed to come out in the same order as keys() $sth->execute(values %sql_data) or die $dbh->errstr; $sth->finish();