title: Perl Repetition after for loop and switch
body: <p>I  have 2 arrays (array1, array2) and I'm tryin to identify strings in common in both and make a substitution, then print out the content of array1. </p>
  
  <p>Element in array2 replaces some elements in array1. In particular if there's :</p>
  
  <pre><code>array1 = 1.txt
  </code></pre>
  
  <p>and</p>
  
  <pre><code>array 2 = 1.txt 0.5
  </code></pre>
  
  <p>array1 will be :</p>
  
  <pre><code>array1 = 1.txt 0.5
  </code></pre>
  
  <p>I've tried to build up this code but it prints out all the elements twice.
  Is there a way to avoid this problem? 
  I know that there's a module in perl called "switch"... Maybe is this the solution? I don't know how it works.</p>
  
  <pre><code>@array1 = qw(76
      38
      0.13213855661882
      0.264277113237639
      1.txt
      ####
      20
      10
      -0.01235
      -0.0247000000000001
      10.txt
      ####
      20
      10
      -0.01235
      -0.0247000000000001
      2.txt
      ####
      46
      14
      0.117232213438735
      0.385191558441558
      10003.txt
      ####);
      @array2 = ("1.txt 0.5", "2.txt 1");
  
  for ($i = 0 ; $i &lt; @array1; $i++){
  for ($k =0; $k &lt; @array2; $k++){
      if (grep /$array1[$i]/, $array2[$k]){
          $array1[$i] =~ s/$array1[$i]/$array2[$k]/;
          print $array1[$i]."\n";
      }
      else {print "RIS ".$array1[$i]."\n";}
  }
  }
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>RIS 76
  RIS 76
  RIS 38
  RIS 38
  RIS 0.13213855661882
  RIS 0.13213855661882
  RIS 0.264277113237639
  RIS 0.264277113237639
  **1.txt 0.5**
  RIS 1.txt 0.5
  RIS ####
  RIS ####
  RIS 20
  RIS 20
  RIS 10
  RIS 10
  RIS -0.01235
  RIS -0.01235
  RIS -0.0247000000000001
  RIS -0.0247000000000001
  RIS 10.txt
  RIS 10.txt
  </code></pre>
  
  <p>Result expected:</p>
  
  <pre><code>RIS 76
      RIS 38
      RIS 0.13213855661882
      RIS 0.264277113237639
      **1.txt 0.5**
      RIS 1.txt 0.5
      RIS ####
      RIS 20
      RIS 10
      RIS -0.01235
      RIS -0.0247000000000001
      RIS 10.txt
  </code></pre>