my $lastpos = 0; while ($lastpos < length $_) { my @matches = (undef x 3); pos = $lastpos; $matches[0] = pos if m/\G([^/?!"]+[.?!"])/gc; #FIRST PRIORITY pos = $lastpos; $matches[1] = pos if m/\G([^:;-]+[:;-])/gc; #SECOND PRIORITY pos = $lastpos; $matches[2] = pos if m/\G(.*(?:\n|\r|\z|$))/gc; #LAST PRIORITY # somehow choose which match to use for the next cycle and set $lastpos here # substr $_, $lastpos, ($matches[$chosen] - $lastpos) # should yield the selected chunk between choosing a match and updating $lastpos }