use strict; use warnings; open my $fh, "<", "file.frg"; while(<$fh>) { if (/^{FRG/../^}/){ if (/^acc:(\d+)/) { print ">$1\n"; } elsif ( /^seq:/ ) { while(<$fh>) { last if /^\./; print; } } } }