in reply to Fastest split possible

For creating an array of substrings, split is probably fastest.

However, you usually want all those substrings so you can do something else with them. If you can process the string in place, it may be faster to do something like:

c:\@Work\Perl\monks>perl -wMstrict -le "my $consonants = qr{ [^aeiouAEIOU]+ }xms; ;; my $s = qq{four score\nand seven\nyears ago\nour fathers\n}; print qq{>$s<}; ;; my $offset = 0; my $pos; while (0 <= ($pos = index $s, qq{\n}, $offset)) { substr($s, $offset, $pos) =~ s{ ($consonants) }{\U$1}xmsg; $offset = ++$pos; } print qq{>$s<}; " >four score and seven years ago our fathers < >FouR SCoRe aND SeVeN YeaRS aGo ouR FaTHeRS <

Update 1: The original code in my reply doesn't do what I imagined (update: the substr length operand is incorrect). Here's code that works as I intended and has a debug print to illustrate what's happening:

c:\@Work\Perl\monks>perl -wMstrict -le "my $consonants = qr{ [^aeiouAEIOU]+ }xms; ;; my $s = qq{four score\nand seven\nyears ago\nour fathers\n}; print qq{>$s<}; ;; my $offset = 0; my $pos; while (0 <= ($pos = index $s, qq{\n}, $offset)) { printf qq{==%s== \n}, substr($s, $offset, $pos-$offset); substr($s, $offset, $pos-$offset) =~ s{ ($consonants) }{\U$1}xmsg; $offset = ++$pos; } print qq{>$s<}; " >four score and seven years ago our fathers < ==four score== ==and seven== ==years ago== ==our fathers== >FouR SCoRe aND SeVeN YeaRS aGo ouR FaTHeRS <

Update 2: This trick (update: i.e., substr returns an lvalue) also works if you want to pass a substring alias to a processing function, but the function has to operate directly on the aliased subroutine argument element in order to preserve the aliasing "chain". Also with an illustrative print point:

c:\@Work\Perl\monks>perl -wMstrict -le "my $consonants = qr{ [^aeiouAEIOU]+ }xms; ;; my $s = qq{four score\nand seven\nyears ago\nour fathers\n}; print qq{>$s<}; ;; my $offset = 0; my $pos; while (0 <= ($pos = index $s, qq{\n}, $offset)) { process(substr $s, $offset, $pos-$offset); $offset = ++$pos; } print qq{>$s<}; ;; sub process { printf qq{==%s== \n}, $_[0]; $_[0] =~ s{ ($consonants) }{\U$1}xmsg; } " >four score and seven years ago our fathers < ==four score== ==and seven== ==years ago== ==our fathers== >FouR SCoRe aND SeVeN YeaRS aGo ouR FaTHeRS <


Give a man a fish:  <%-{-{-{-<