my $ISIN = / ^ <[A..Z]>**2 <[A..Z0..9]>**9 <[0..9]> $ <?{ luhn-test $/.comb.map({ :36($_) }).join }>/;sub luhn-test ($number --> Bool) { my @digits = $number.comb.reverse; my $sum = @digits[0,2...*].sum + @digits[1,3...*].map({ |($_ * 2).comb }).sum; return $sum %% 10;}# Testing:say "$_ is { m/$ISIN/ ?? "valid" !! "not valid"}" for <US0378331005US0373831005U50378331005US03378331005AU0000XVGZA3AU0000VXGZA3FR0000988040>;
Output:
US0378331005 is valid
US0373831005 is not valid
U50378331005 is not valid
US03378331005 is not valid
AU0000XVGZA3 is valid
AU0000VXGZA3 is valid
FR0000988040 is valid