use strict; my $operator=; my $op_map={}; my $one=10; my $two=5; chomp $operator; define_op_map(); if ( defined ($op_map->{$operator}) ) { &{$op_map->{$operator}}; } else { print "This op is undefined. Executing it might end the universe as we know it.\n"; } sub define_op_map { $op_map->{'+'}=sub{print $one + $two . "\n"}; $op_map->{'-'}=sub{print $one - $two . "\n"}; $op_map->{'*'}=sub{print $one * $two . "\n"}; $op_map->{'/'}=sub{print $one / $two . "\n"}; } #### $op_map->{'camel'}=sub{print "$one is a $two with humps.\n"};