#!/usr/bin/perl use warnings; use strict; my %contig; open my $CNTG, '<', 'contig_names' or die $!; while (<$CNTG>) { chomp; s/_//; # Remove the underscore, as it doesn't appear in the genbank. $contig{$_} = 1; } local $/ = '//'; # Read the file one record a time. open my $GB, '<', 'genbank' or die $!; while (<$GB>) { if (my ($id) = /LOCUS \s+ \S+ _ (contig [0-9]+)/x) { print if $contig{$id}; } }