{ my %dispatch = (); sub arbitrary_operator_maker { my $operation = shift; my $num_elements = shift; my $dispatch_key = "$operation$num_elements"; return $dispatch{$dispatch_key} if $dispatch{$dispatch_key}; my $built = join $operation, map {'$_[' . $_ . ']'} (0..$num_elements - 1); return $dispatch{$dispatch_key} = eval "sub { $built }"; } }