sub fun{ return sub {return 'foo has value $foo'); } ... $coderef = fun; $foo = 7; $str = &$coderef;