my %hash2 =( '1' => 2, '3' => 5, '4' => 2,); #### $VAR1 = { '3-3' => 5, '3-4' => 10, '1-1' => 2, '3-1' => 10, '1-4' => 4, '4-4' => 2,#ends here }; #### use strict; use warnings; use Data::Dumper; #print Dumper \%hash2; my %spair = (); my $prod; foreach my $si (keys %hash2) { foreach my $sn (keys %hash2) { if ($si == $sn) { $prod = $hash2{$si}; } else { $prod = $hash2{$si}*$hash2{$sn}; } $spair{$si."-".$sn} = $prod; } } print Dumper \%spair; #### $VAR1 = { '3-3' => 5, '3-4' => 10, '1-1' => 2, '3-1' => 10, '1-4' => 4, '4-4' => 2, '4-1' => 4, #repeat '1-3' => 10,#repeat '4-3' => 10 #repeat };