use strict; my $n = $ARGV[0] || 1; my %hash1 = (); for (my $i = 0; $i <= 9999; $i++) { $hash1{"foo_$i"} = $i; } my %hash2 = (); for (my $i = 1; $i <= $n; $i++) { foreach (keys %hash1) { $hash2{$_} += $hash1{$_}; } } print "$hash1{foo_1} $hash1{foo_9999} $hash2{foo_1} $hash2{foo_9999}\n";