#!/usr/bin/env perl use 5.010; use strict; use warnings; my $cfg = { x => 'cat' }; say 'INITIAL: ', $cfg; example_sub(); $cfg->{x} = 'mouse'; say 'CHANGE1: ', $cfg; example_sub(); $cfg = { x => 'rat' }; say 'CHANGE2: ', $cfg; example_sub(); sub example_sub { say cfg_cache()->{x}; } sub cfg_cache { state $cfg = $cfg; say 'CACHED: ', $cfg; return $cfg; }