my @some-numbers = 3, 1, 4, 1, 5, 9, 2, 6;
my @to-match = 9, 7, 1, 2, 1, 1;
my @matched;
my %histogram;
for @some-numbers -> $n { %histogram{$n}++ };
for @to-match -> $n {
next if not defined %histogram{$n};
if %histogram{$n} > 0 {
push @matched, $n;
%histogram{$n}--;
}
};
say @matched;