use strict; use warnings; my $group = "a!" x 50001; my $count = 0; my $pos = 0; substr $group, $pos, 1, "\n" while( ($pos = index( $group, "!", $pos )) > -1 and $count++ < 50000 ); print $group;