use v6; my @occurrences = gather for lines() -> $line { take (+$0, ~$1) if $line ~~ /^ \s* (\d+) \s+ (.*) $/; }; my $total = [+] @occurrences».[0]; for @occurrences -> ($count, $text) { printf("%.3f %s\n", $count * 100 / $total, $text); }