in reply to global match except last one
Another way:
...but alas it is very slow, producing half as many loops as happy.barney's lookaround. Who would have thought that a zero width match could be replaced by something?use strict; use warnings; use 5.010; my @strings = qw{ aB namesCanBeDifferentAny helloWorld }; for my $str (@strings) { $str =~ s{ ( [a-z]* ) ( [A-Z] [a-z]* ) } {\U$1_$2}xmsg; say $str; } --output:-- A_B NAMES_CAN_BE_DIFFERENT_ANY HELLO_WORLD
|
|---|