my %foo_cache; sub foo { @{$foo_cache{join ",", @_} ||= [ do { ... rest of sub goes here }]} }