In animals, PIWI-interacting RNAs (piRNAs) of 21-35 nucleotides in length silence transposable elements, regulate gene expression and fight viral infection. piRNAs guide PIWI proteins to cleave target RNA, promote heterochromatin assembly and methylate DNA. The architecture of the piRNA pathway allows it both to provide adaptive, sequence-based immunity to rapidly evolving viruses and transposons and to regulate conserved host genes. piRNAs silence transposons in the germ line of most animals, whereas somatic piRNA functions have been lost, gained and lost again across evolution. Moreover, most piRNA pathway proteins are deeply conserved, but different animals employ remarkably divergent strategies to produce piRNA precursor transcripts. Here, we discuss how a common piRNA pathway allows animals to recognize diverse targets, ranging from selfish genetic elements to genes essential for gametogenesis.