Animals recognize mechanosensory stimuli and generate targeted responses. Flies perform distinct leg rubbing movements depending on which of the legs is stimulated. While the leg that receives stimulus is always involved in cleaning, different adjacent legs are recruited. For front and hind legs, the contralateral homolog or ipsilateral middle leg is used, but for the middle leg, one or both hind legs are engaged. Here, we identify six segmentally repeated command-like interneurons, LegPNs, whose activation induces leg rubbing. Sensorimotor circuits, repeated in each neuromere, include mechanosensory inputs and reciprocal excitatory connections with pre-motor LegPLs. Activation of LegPLs causes leg flexion. There are segmental differences in the circuits downstream of LegPNs for the middle legs-T2 LegPCs lack commissural connections but include additional ipsilateral intersegmental projections. LegPC activation causes simultaneous front and back leg rubbing. These behavioral and anatomical results demonstrate how shared and modified serially homologous neural circuits coordinate segmentally distinct grooming movements.