my @array; while () { last if /^d/ } #discard until the first match while () { if ( @array and /^d/ ) { process_array( @array ); undef @array; next; } push @array, $_; }