The length of the tail of bacteriophages is controlled by a protein which acts as a molecular ruler. The needle of the injectisome, which is assembled by the polymerization of subunits that are exported through the nascent injectisome, is functionally related to the tail of bacteriophages. Interestingly, its length is controlled by a protein, which is itself exported and acts as a molecular ruler that is coupled to a substrate specificity switch. The bacterial flagellum is evolutionarily related to the injectisome. The length of the hook is also controlled by a secreted protein. This protein acts as a substrate specificity switch and, possibly, also as a ruler.