in reply to Iterating through files and arrays simultaneously

If you're happy to slurp the file
my @data = do { open(my $fh, '<', 'yourfile') or die("ack: $!"); local $/ = '>gb|'; scalar <$fh>; # first read will be useless <$fh>; }; my @nums = qw( 456-3210 4670-5490 ); for my $n (@nums) { print map { '>gb|' . substr($_, 0, -4) } grep { $_ =~ /^$n/ } @data; }
So that will create an array consisting of chunks of the file delimited by >gb|, and then print any chunk that matches any of thenumber sequences in @nums.
HTH

_________
broquaint