in reply to remove part of string (DNA)

A general FASTA-processing loop looks like this:
# Always read up to the next ">" at the beginning of a line: $/ = "\n>"; getc(INPUT); # skip the first ">" while (<INPUT>) { # remove "\n>" chomp; # first line is the ID, the rest is the sequence my ($id, $seq) = /^([^\n]*)\n(.*)/s; # remove whitespace in the sequence $seq =~ s/\s+//g; # do something with $id and $seq ... # output the result in 72-column format print OUTPUT ">$id\n"; print OUTPUT "$1\n" while $seq =~ /(.{1,72})/g; }
You'll want to read and write the data as you go instead of storing it in an array, and check for all the primers in one pass.