use Modern::Perl;$_=' action action '; $_{'s'} = { jeopardy =>"21"}; $_{'qd'} = { action => 'default' }; sub dbl { say "this should only calc once"; $_{'dbl'}->{$_[0]} = $_[0]*2; } sub use { $_{'use'}->{$_[0]} = &simulate_opening_file; } sub simulate_opening_file { say "this should only slurp once"; "The answer is jeopardy" }; while (/<([^<]+?)>([^<]*?)<\/>/) { my $l=$+[0]-$-[0]; no strict 'refs'; my $r = $_{$1}->{$2} ||= $1->($2); substr($_,$-[0],$l,$r); } say;