title: Backreferences to constituents of a group consisting of a fixed number of repetitions
body: <p>I want to find a group that is repeated x times after each other, eg, five times a letter-digit combo separated by a space. I can use a simple repetition syntax, eg <code>(?:\w\d ){5}</code>. </p>
  
  <p>I then want to replace the space in this 5x letter-digit with something else. For this, I try to backreference each of the letter-digit combos (without the space) by placing parentheses around it: <code>(?:(\w\d) ){5}</code>. Unfortunately, all five are store in <code>$1</code>, ie, <code>$1</code> gets overwritten every time it matches.</p>
  
  <p>So, is there a way to avoid this overwriting? Or is there a way to replace something only in a substring?</p>
  
  <p>EDIT:</p>
  
  <p>Example input string: <code>A1 A3 A4 B6 ::: A1 A3 A4 C5 B6</code></p>
  
  <p>Desired output string: <code>A1 A3 A4 B6 ::: A1-A3-A4-C5-B6</code></p>
  
  <p>That means, replace the space only if there are five of them. Implemented in Perl.</p>