您必须捕获匹配的字符串并单独处理.
原文链接:https://www.f2er.com/regex/356696.html此代码演示
use strict; use warnings; my $str = '> plantagenetgoosewagonattributes'; if ($str =~ />(.*)[^a]+/) { my $substr = $1; my %counts; $counts{$_}++ for $substr =~ /./g; print "'$_' - $counts{$_}\n" for sort keys %counts; }
产量
' ' - 1 'a' - 4 'b' - 1 'e' - 4 'g' - 3 'i' - 1 'l' - 1 'n' - 3 'o' - 3 'p' - 1 'r' - 1 's' - 1 't' - 5 'u' - 1 'w' - 1