title: How can I select certain elements from a Perl array?
body: <p>I want to search for all elements in an array which have the same starting set of characters as an element in another array. To make it clear:</p>
  
  <pre><code>@array = ("1a","9","3c");
  @temp =("1","2","3");
  </code></pre>
  
  <p>I want to print only 1a and 3c. When I try to use the following program it prints out all the elements in the array instead of the two I want:</p>
  
  <pre><code>foreach $word (@temp)
  {
      if( grep /^$word/ , @array) 
      {
          print $_;
      }
  }
  </code></pre>
  
  <p>Any insights will be appreciated.</p>