while ( ) { chomp; last if /^SEQRES[\s]{2,5}2/; # or my $num = /^SEQRES[\s]{2,5}(\d)/; last if $num == 2;