The hsd genes of Mycoplasma pulmonis encode restriction and modification enzymes exhibiting a high degree of sequence similarity to the type I enzymes of enteric bacteria. The S subunits of type I systems dictate the DNA sequence specificity of the holoenzyme and are required for both the restriction and the modification reactions. The M. pulmonis chromosome has two hsd loci, both of which contain two hsdS genes each and are complex, site-specific DNA inversion systems. Embedded within the coding region of each hsdS gene are a minimum of three sites at which DNA inversions occur to generate extensive amino acid sequence variations in the predicted S subunits. We show that the polymorphic hsdS genes produced by gene rearrangement encode a family of functional S subunits with differing DNA sequence specificities. In addition to creating polymorphisms in hsdS sequences, DNA inversions regulate the phase-variable production of restriction activity because the other genes required for restriction activity (hsdR and hsdM) are expressed only from loci that are oriented appropriately in the chromosome relative to the hsd promoter. These data cast doubt on the prevailing paradigms that restriction systems are either selfish or function to confer protection from invasion by foreign DNA.