# first, generate fixed-precision strings for magnitudes # and bin values: my @mag_keys = map { sprintf("%.1f", $_/10) } ( 50 .. 89 ); my @bins = qw/0 0.1 0.3 1 3 10 30 1000/; # now initialize hash bins for counting: # (this is probably unnecessary, unless you're re-using # the hash on multiple separate data sets) my %n; for my $mag ( @mag_keys ) { for my $bin ( @bins ) { $n{$mag}{$bin} = 0; } }