title: Pattern matching with array in Perl
body: <p>This is the script I am using to pattern match. I m not getting the exact output which I need please help me out..  </p>
  
  <pre><code>#!/usr/bin/perl5.14.4
  open(LIST, "/home/guest/Desktop/hpresult.txt") 
      or die ("Couldn't open the  Result");
  @list = &lt;LIST&gt;;
  close LIST;
  open(OUTPUT, "&gt;/home/guest/Desktop/sortresult3") 
      or die ("couldn't write the file");
  $line = (@list);
  foreach $line(@list) {
      if($line =~ m/&gt;/g) {
          $pdbid = substr($line, 0);
      }
      if($line =~ m/Found/g) {
          $id = $line;
          print OUTPUT $pdbid . $id;
      }
  }
  </code></pre>
  
  <p>INPUT  </p>
  
  <pre><code>hpresult.txt  
  &gt;3ior_B  
  Found PPPPPPPPPPP at 397 to 407 of length 11  
  Found QQQQQQQQQ at 388 to 396 of length 9  
  
  &gt;3ior_C  
  Found QQQQQQQQQQQQQ at 388 to 400 of length 13  
  
  &gt;3ios_A  
  
  &gt;3iot_A
  </code></pre>
  
  <p>OUTPUT  (Which I m getting)</p>
  
  <pre><code>&gt;3ior_B  
  Found PPPPPPPPPPP at 397 to 407 of length 11  
  &gt;3ior_B  
  Found QQQQQQQQQ at 388 to 396 of length 9  
  &gt;3ior_C  
  Found QQQQQQQQQQQQQ at 388 to 400 of length 13  
  </code></pre>
  
  <p>Desired OUTPUT  </p>
  
  <pre><code>&gt;3ior_B  
  Found PPPPPPPPPPP at 397 to 407 of length 11  
  Found QQQQQQQQQ at 388 to 396 of length 9  
  
  &gt;3ior_C  
  Found QQQQQQQQQQQQQ at 388 to 400 of length 13  
  </code></pre>
  
  <p>Please help me regarding this..</p>