in reply to compare lists and delete unwanted from file

Perhaps you want something like this (UNTESTED):

use strict; use warnings; my $list_file = '/g/Viruses/prophage_data/emptySeqList_aa.txt'; my $ptt_file = '/g/Viruses/prophage_data/prophage_region.ptt1'; ## list of 83 to remove from ptt file open my $IN, '<', $list_file or die "Cannot open '$list_file' because: + $!"; my %empty_geneids; while ( <$IN> ) { my ( $header ) = split; if ( /^>([^_]+_[^_]+)/ ) { $empty_geneids{ $1 } = 1; print "empty gene_id from list file\t$1\n"; } } close $IN; my $empty_geneids_pattern = join '|', keys %empty_geneids; open my $PTT, '<', $ptt_file or die "Cannot open '$ptt_file' because: +$!"; open my $OUT, '>', "$ptt_file.noEmpties" or die "Cannot open '$ptt_fil +e.noEmpties' because: $!"; while ( <$PTT> ) { next if /$empty_geneids_pattern/; print $OUT $_; } close $OUT; close $PTT;