Tandemly repeated DNA sequences are highly dynamic components of genomes. Most repeats are in intergenic regions, but some are in coding sequences or pseudogenes. In humans, expansion of intragenic triplet repeats is associated with various diseases, including Huntington chorea and fragile X syndrome. The persistence of intragenic repeats in genomes suggests that there is a compensating benefit. Here we show that in the genome of Saccharomyces cerevisiae, most genes containing intragenic repeats encode cell-wall proteins. The repeats trigger frequent recombination events in the gene or between the gene and a pseudogene, causing expansion and contraction in the gene size. This size variation creates quantitative alterations in phenotypes (e.g., adhesion, flocculation or biofilm formation). We propose that variation in intragenic repeat number provides the functional diversity of cell surface antigens that, in fungi and other pathogens, allows rapid adaptation to the environment and elusion of the host immune system.