my $update = { ADDRESS => 'test', customer_name => 'eric' }; my @cols = sort grep { defined $update->{$_}} keys %$update; my $sql = join (",", map { "$_ = ?" } @cols ); print "UPDATE test SET $sql WHERE id = ?"; #then you can use it like: # $dbh->execute("UPDATE test SET $sql WHERE id = ?",undef, map {%update{$_}} @cols, $id);