#!/usr/bin/perl use strict; use warnings; use List::PowerSet qw(powerset); my $nums = '0-200 200-400 400-600 600-800 800-1000 1000-2000 0,1800'; my %hash; @hash{ split /\D+/, $nums } = (); my @sorted = sort {$a<=> $b} keys %hash; my $start = shift @sorted; my $end = pop @sorted; my $ps = powerset(@sorted); for my $set (@$ps) { print join("-", $start, @$set, $end), "\n"; } __END__ 0-200-400-600-800-1000-1800-2000 0-400-600-800-1000-1800-2000 0-200-600-800-1000-1800-2000 0-600-800-1000-1800-2000 0-200-400-800-1000-1800-2000 0-400-800-1000-1800-2000 0-200-800-1000-1800-2000 0-800-1000-1800-2000 0-200-400-600-1000-1800-2000 0-400-600-1000-1800-2000 0-200-600-1000-1800-2000 0-600-1000-1800-2000 0-200-400-1000-1800-2000 0-400-1000-1800-2000 0-200-1000-1800-2000 0-1000-1800-2000 0-200-400-600-800-1800-2000 0-400-600-800-1800-2000 0-200-600-800-1800-2000 0-600-800-1800-2000 0-200-400-800-1800-2000 0-400-800-1800-2000 0-200-800-1800-2000 0-800-1800-2000 0-200-400-600-1800-2000 0-400-600-1800-2000 0-200-600-1800-2000 0-600-1800-2000 0-200-400-1800-2000 0-400-1800-2000 0-200-1800-2000 0-1800-2000 0-200-400-600-800-1000-2000 0-400-600-800-1000-2000 0-200-600-800-1000-2000 0-600-800-1000-2000 0-200-400-800-1000-2000 0-400-800-1000-2000 0-200-800-1000-2000 0-800-1000-2000 0-200-400-600-1000-2000 0-400-600-1000-2000 0-200-600-1000-2000 0-600-1000-2000 0-200-400-1000-2000 0-400-1000-2000 0-200-1000-2000 0-1000-2000 0-200-400-600-800-2000 0-400-600-800-2000 0-200-600-800-2000 0-600-800-2000 0-200-400-800-2000 0-400-800-2000 0-200-800-2000 0-800-2000 0-200-400-600-2000 0-400-600-2000 0-200-600-2000 0-600-2000 0-200-400-2000 0-400-2000 0-200-2000 0-2000