use strict; use warnings; my $value_buckets = { 'first half' => sub { print qq{first half!\n} }, 'second half' => sub { print qq{second half!\n} }, 'third half' => sub { print qq{third half!\n} }, 'not found' => sub { print qq{not found!\n} }, }; my $key = compute_key(42); $value_buckets->{$key}->(); # just an example, could be anything to derive a hash # key from $value sub compute_key { my $value = shift; if ( $value > 0 and $value < 33 ) { return 'first half'; } elsif ( $value >= 33 and $value <= 66 ) { return 'second half'; } elsif ( $value >= 67 and $value <= 100 ) { return 'third half'; } # last resort return 'not found'; } #### # perl test.pl second half!