r2h(..) { my $dbh = shift; my $table_name = shift; my $col_name = shift; my $v = shift; my $where = shift; my @w_conds = @_; my $sql = ... if($where) { $sql .= "($where) and `$col_name`= ?". } else { $sql .= "where `$col_name` = ?"; } ... }