get qr/(?hi|hello)/ => sub { print $+{greet}, " there!\n"; } #### $ cat pm_1198334.pl #!env perl my @handlers; sub get { my ($key, $action) = @_; push @handlers, [ $key, $action ]; } sub handle { my $request = shift; for my $rh (@handlers) { my ($key, $action) = @$rh; if ("Regexp" eq ref $key) { return $action->($request) if $request =~ $key; } elsif ("" eq ref $key) { return $action->($request) if $key eq $request; } else { print "How do I handle <", ref($key), ">?\n"; } } print "Sorry, I don't know what <$request> means!\n"; } get foo => sub { print "Pizza time!\n" }; get qr/(?hi|hello)/ => sub { print $+{greet}, " there!\n" }; handle("foo"); handle("hi robot!"); handle("helloooooooo Nurse!"); Roboticus@Waubli ~ $ perl pm_1198334.pl Pizza time! hi there! hello there!