#!/usr/bin/perl -w use strict; use Data::Dumper; # The HoA below may come in varying # sizes: from "key1" to "key 50" my $hash = { 'key1' => [ 1, 2, 3, 4 ], 'key2' => [ 10, 20, 30 ], 'key3' => [ 100, 200, 300 ], 'key4' => [ 'a','b','c','dood'] }; my (@b, @base); #compute combos for(sort keys %{$hash}){ concat_arrays(\@b, $hash->{$_}); } #filter computations @base = grep{ my $count = () = $_ =~ m/\-/g; ($count == (scalar(keys %{$hash})-1)); }sort @base; #double check print $_."\n" for(@base); sub concat_arrays { my ($baseref, $newref) = @_; foreach my $new (@{$newref}){ if(scalar(@{$baseref})){ foreach my $base (@{$baseref}){ push @base, $base." - ".$new; } }else{ push @base, $new; } } @b = @base; }