use strict; use warnings; sub action_1_to_999 { print "1 to 999\n"; } my %dispatch = ( 0 => sub { print "Zero\n" }, map { $_ => \&action_1_to_999 } ( 1 .. 999 ), 1000 => sub { print "1e3\n" }, ); $dispatch{0}->(); $dispatch{23}->(); #### map { $_ => \&action_124_to_140 } ( 124 .. 140, 143 .. 146, 148 .. 149, 160 .. 169, 181 .. 189 ), #### map { $_ => \&action_89930_to_89999 } ( 89930 .. 89999 ), #### $dispatch{1000}->(); #### #!/usr/bin/perl -w use strict; use warnings; sub action_124_to_140 { return 'Range 124 to 140, plus ...'; } sub action_089930_to_089999 { return 'Range 89930 to 89999'; } my $href_dispatch_table = { # Single Numbers: '01' => sub { return 'Geographic Numbers'; }, '02' => sub { return 'Geographic Numbers'; }, '055' => sub { return 'Corporate Numbers'; }, '071' => sub { return 'Mobile Services'; }, # ... and etc. # Ranges: # 124 to 140, 143 to 146, # 148 to 149, 160 to 169, and # 181 to 189 inclusive map { $_ => \&action_124_to_140 } ( 124 .. 140, 143 .. 146, 148 .. 149, 160 .. 169, 181 .. 189 ), # 089930 to 089999 inclusive map { $_ => \&action_89930_to_89999 } ( 89930 .. 89999 ), }; while () { chomp; if ( exists $href_dispatch_table->{$_} ) { print $_, "\t", $href_dispatch_table->{$_}->(); print "\n"; } else { print "\t\t\"$_\" does not exist in the dispatch table!\n"; } } __DATA__ 01 1 56 55 055 124 0124 0140 140 145 89930 89999 89963