my $dbquery eq "UPDATE table_name SET column_name=$inputUpdate[0] WHERE column_name=$input[1]"; #### use strict; my @columns = qw(name title state); my @input = qw(foo bar baz); my @inputUpdate = qw(boing bar boo); my $table_name = 'mytable'; my @new_value_clause = map { "$columns[$_] = ?" } grep { $input[$_] ne $inputUpdate[$_] } 0..$#inputUpdate; my @where_clause = map { "$columns[$_] = ?" } 0..$#input; my $sql = join "\n", "UPDATE $table_name", "SET " . join ",", @new_value_clause, "WHERE " . join " and ", @where_clause; my $sth = $dbh->prepare($sql); $dbh->execute(@inputUpdate, @input);