sub word_to_indicator { my($n, $w) = @_; my($p, $d) = 0; reverse map { $p += $d = chr(ord("A") + $_) eq substr($w, $p, 1) ? 1 : 0; $d; } 0 .. $n - 1; } if (1) { # here, N = 5, K = 2. my @combination = qw{AB AC AD AE BC BD BE CD CE DE}; for my $combination (@combination) { my @indicator = word_to_indicator(5, $combination); my($N, $K, $rank, $C) = perm_decode(@indicator); print "$combination : @indicator : $N $K $C $rank\n"; } }