use String::Combination qw(combination); my @comb = combination('12345678',8); print "@comb[6..12]\n@comb[62..68]\n";