$functions{$var1} returned undef because none of the regexp keys matched, so $functions{$var1}->($var2) gives that error. The fix is to check whether a key was found in the hash:
my $handler = $functions{$var1}; if (not defined $handler) { ... } my $result = $handler->($var2);
Perhaps it's because you never assigned a value to $var1?
In reply to Re: Using a regex as a hash key
by ikegami
in thread Using a regex as a hash key
by jivanm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |