my @conditions = grep length, $b, $c; $string = $a; $string .= " where ".join(" and ", @conditions) if @conditions;