my $f = "%0".(($b + ($b & 1)) >> 2)."X" ; my $cnt = 0 ; $cnt += sprintf($f, $_) =~ m/[012348C]/ for 0..((2**$b)-1) ;