# @TERMS defined elsewhere my $query = 'SELECT '; foreach my $term (@TERMS) { $query .= "$term,"; } $query .= 'WHERE foo = ?';