#!/usr/bin/perl

use strict;
use warnings;

die "usage: select.pl fasta_file gene1 gene2 ..." if @ARGV<2;

my %names;
foreach (@ARGV[1..$#ARGV]) {
  $names{$_} = 1;
}

my $collection = 0;

open(FILE, $ARGV[0]);
while (<FILE>) {
  if (/^>/) {
    my @fields = split;
    if (exists $names{substr($fields[0],1)}) {
      print;
      $collection = 1;
    } else {
      $collection = 0;
    }
  } elsif ($collection) {
    print;
  }
}
  
