while ( ) { chomp; if ( /^SEQRES[\s]{2,5}1\s/ ) { print "$_\n"; print OUTFILE "$_\n"; } elsif ( /^SEQRES[\s]{2,5}2\s/ ) { last; } }