title: perl- extract duplicate sequences from a multi-fasta file
body: <p>I have a big fasta file <strong>input.fasta</strong> which consists many duplicate sequences. I want to enter a header name and extract out all the sequences with the matching header. I know this could be done easily done with awk/sed/grep but I need a Perl code.</p>
  
  <p><strong>input.fasta</strong></p>
  
  <pre><code>&gt;OGH38127_some_organism
  PAAALGFSHLARQEDSALTPKHYTWTAPGEGDVRAPCPVLNTLANHEFLPHNGKNITVDK
  AITALGDAMNISPALATTFFTGGLKTNPTPNATWFDLDMLHKHNVLEHDGSLSRRDMHFD
  TSNKFDAATFANFLSYFDANATVLGVNETADARARHAYDMSKMNPEFTITSSMLPIMVGE
  SVMMMLVWGSVEEPGAQRDYFEYFFRNERLPVELGWTPGETEIGVPVVTAMITAMVAASP
  TDVP
  &gt;ABC14110_some_different_org_name
  WWVAPGPGDSRGPCPGLNTLANHGYLPHDGKGITLSILADAMLDGFNIARSDALLLFTQ
  AIRTSPQYPATNSFNLHDLGRDQLNRHNVLEHDASLSRADDFFGSNHIFNETVFDESRAY
  AMLANSKIARQINSKAFNPQYKFTSKTEQFSLGEIAAPIIAFGNSTSGEVNRTLVEYFFM
  NERLPIELGWKKSEDGIALDDILRVTQMISKAASLITPSALSWTAETLTP
  &gt;OGH38127_some_organism
  LPWSRPGPGAVRAPCPMLNTLANHGFLPHDGKNISEARTVQALGRALNIEKELSQFLFEK
  ALTTNPHTNATTFSLNDLSRHNLLEHDASLSRQDAYFGDNHDFNQTIFDETRSYWPHPVI
  DIQAAALSRQARVNTSIAKNPTYNMSELGLDFSYGETAAYILILGDKDFGKVNRSWVEYL
  FENERLPVELGWTRHNETITSDDLNTMLEKVVN
  .
  .
  .
  </code></pre>
  
  <p>I have tried with the following script but it is not giving any output.</p>
  
  <p><strong>script.pl</strong></p>
  
  <pre><code>#!/perl/bin/perl -w
  use strict;
  use warnings;
  
  print "Enter a fasta header to search for:\n";
  my $head = &lt;&gt;;
  
  my $file = "input.fasta";
  open (READ, "$file") || die "Cannot open $file: $!.\n";
  my %seqs;
  my $header;
  
  while (my $line = &lt;READ&gt;){
      chomp $line;
      $line =~ s/^&gt;(.*)\n//;
      if ($line =~ m/$head/){
          $header = $1;
      }
  }
  close (READ);
  
  open( my $out , "&gt;", "out.fasta" ) or die $!;
  
  my @count_seq = keys %seqs;
  foreach (@count_seq){
      print $out $header, "\n";
      print $out $seqs{$header}, "\n";
  }
  
  exit;
  </code></pre>
  
  <p>Please help me correct this script.
  Thanks!</p>