if (some_perl_code_condition) { push @where, 'a.somedata5 <= ?'; push @bind, $somedata5_max } # ... $sql = $select . join(' AND ', @where) . $order; # and use @bind for the execute statement