use strict; use warnings; my $idsfile = "sample_IDs.txt"; my $seqfile = "sample_reads.fasta"; my %ids = (); open FILE, $idsfile; while() { chomp; $ids{$_} += 1; } close FILE; local $/ = "\n>"; # read by FASTA record open FASTA, $seqfile; while () { chomp; my $seq = $_; my ($id) = $seq =~ /^>*(\S+)/; # parse ID as first word in FASTA header if (exists($ids{$id})) { $seq =~ s/^>*.+\n//; # remove FASTA header $seq =~ s/\n//g; # remove endlines print "$seq\n"; } } close FASTA;