use Memoize; memoize("handle_for_name"); sub handle_for_name { my $f = shift; open my $h, '<', $f or die "Can't open file '$f': $!"; return $h; }