my @array=(['john','tom','peter'],['rose','teak'],['car','truck','jeep'],['trees','plants'],['good','bad','ugly']); my @arrayindex=(3,1); my %hash=(); foreach my $i (@{$array[$arrayindex[0]]}) { foreach my $j (@{$array[$arrayindex[1]]}) { $hash{"$i $j"}=1; } } foreach my $i (keys %hash) { print "$i=>$hash{$i}\n"; } The output of the program is a hash whose keys represent all possible combination of values: trees rose=>1; trees teak=>1; plants rose=>1; plants teak=>1;