title: perl script to compare an array lines and print the line if first and third string in the line is matching
body: <p>I have an array <code>@array1</code> containing these lines.</p>
  
  <pre><code>QA.15|foo123|P101|SR234 2345
  QA.15|foo124|P102|SR236 2234
  QA.15|foo125|P103|SR234 2235
  QA.15|foo123|P102|SR235 2322    
  QA.15|foo123|P103|SR234 2341
  </code></pre>
  
  <p>I have split <code>@array1</code> using <code>[\\||\s+]</code> as a delimiter, and the resulting <code>@array2</code> is:</p>
  
  <pre><code>QA.15 foo123 P101 SR234 2345 ==&gt; Matched
  QA.15 foo124 P102 SR236 2234
  QA.15 foo125 P103 SR234 2235
  QA.15 foo123 P102 SR235 2322
  QA.15 foo123 P103 SR234 2341 ==&gt; Matched
  </code></pre>
  
  <p>I need an output such that, first and third string of the line must be matched against each array lines and matched lines must be captured or printed out.</p>
  
  <p><strong>Expected output</strong></p>
  
  <pre><code>QA.15 foo123 P101 SR234 2345 
  QA.15 foo123 P103 SR234 2341
  </code></pre>
  
  <p>Below code is what I am trying to get the result which isnt working.</p>
  
  <pre><code>my $file = "data.file";
  my @array1 = `cat $file | grep -i 'P80*'`;
  my @array2; 
  foreach my $line (@array1)
  { 
      my @split = split /\|/, $line;
      push @array2, @split;
  }
  my @matched_lines;
  for (my $i = 0; $i &lt;= $#array1; $i++)
  {
      foreach (@array2)
      { 
          if ($array2[1] &amp;&amp; $array2[3] =~ m/$array1[$i++]/)
          { 
              push @matched_lines, $array1[$i];
          }
      }
   }
  
   print "@matched_lines\n";
  </code></pre>