my $i; while ( my $seq = $seqio->next_seq() ) { # do something with the data print $seq->display_id, "\n"; last if $i++ > 5; }