my @array; push @array, "one"; push @array, "two"; push @array, "three"; psuh @array, "four"; my $k=0; my @combos; for(combinations(@array)) { $combos[$k] = join("|",@$_); $k++; } sub combinations { return [] unless @_; my $first = shift; my @rest = combinations(@_); return @rest, map { [$first, @$_] } @rest; } #### $VAR1 = [ '', 'four', 'three', 'three|four', 'two', 'two|four', 'two|three', 'two|three|four', 'one', 'one|four', 'one|three', 'one|three|four', 'one|two', 'one|two|four', 'one|two|three', 'one|two|three|four' ]; #### $VAR1 = [ 'one|two|three|four' 'two|three|four', 'one|three|four', 'one|two|three', 'one|two|four', 'three|four', 'two|three', 'one|three', 'two|four', 'one|four', 'one|two', 'three', 'four', 'two', 'one', '' ];