@fields = qw(Name ID Age Key); #assuming $dbh and $q exist, and primary key name in $key #we don't want to change the value of the key! my $statement = 'update my_table '.join(",", map {"set $_ = ?"} grep(!/^$key$/, @fields))." where $key=?"; my $sth = $dbh->prepare($statement); $sth->execute(map({$q->param($_)} @fields));