use strict; use warnings; # read file 1 into hash, don't forget to chomp; # left as exercise # result should look like this: my %file1 = ( '>SR1.2' => 1, '>SR1.3' => 1, ); # loop over file two while(){ next unless /^(>.*?)\s/ and exists $file1{$1}; print $_...; } __DATA__ >SR1.1 HWI-ST ATGCTGCT TCGTCGAT CTGATCAGCTAC >SR1.2 HWI-ST0 TTTTGCTGCT TCGTTGGG CTTTATCAGCTAC >SR1.3 HWI-ST0787 GGGGGCTGCT AATCGTCGAT AACTGATCAGCTAC >SR1.4 HWI-ST0787 GGGGGCTGCT AATCGTCGAT AACTGATCAGCTAC