for my $x (sort keys %hash) { for my $y (sort grep { $_ ne $x } keys %hash) { printf "%s * %s = %d\n", $x, $y, $hash{$x} * $hash{$y}; } }