in reply to Multi_captures needed
You can have something that kind of behaves like "multiple captures" by matching in list context and using look ahead assertions to make sure the current match still allows for the rest of the string to match. Not sure about performance, but it's a solution that doesn't require to embed code in the regex.
You know that there is a match or the end of the string after each match, so after the first match you know the regex will always succeed at the current position. Adding \G can make that more explicit, and force the overall match to start at position 0.use Data::Dump qw/pp/; chomp( (undef, $_, undef, @words) = <> ); # If multiple words are identical as lowercase, only the last one will + be kept %restore_case = map { lc reverse, $_ } @words; $list = join '|', keys %restore_case; # Match any word in the list, only if it can be followed by words in t +he list until the end of the string my @result = map { $restore_case{$_} } /($list)(?=(?:$list)*$)/g; pp @result;
|
|---|