CRISPR/Cas (Clustered Regularly Interspaced Short Palindromic Repeats/CRISPR-associated genes) is a small RNA-based adaptive prokaryotic immunity system that functions by acquisition of short fragments of DNA (mainly from foreign invaders such as viruses and plasmids) and subsequent destruction of DNA with sequences matching acquired fragments. Some mutations in foreign DNA that affect the match prevent CRISPR/Cas defensive function. Here we show that matching sequences that are no longer able to elicit defense, still guide the CRISPR/Cas acquisition machinery to foreign DNA, thus making the spacer acquisition process adaptive and leading to restoration of CRISPR/Cas-mediated protection. We present evidence suggesting that after initial recognition of partially matching foreign DNA, the CRISPR/Cas acquisition machinery moves along the DNA molecule, occasionally selecting fragments to be incorporated into the CRISPR locus. Our results explain how adaptive CRISPR/Cas immunity becomes specifically directed towards foreign DNA, allowing bacteria to efficiently counter individual viral mutants that avoid CRISPR/Cas defense.