sub x { my $coderef = shift; use Data::Dumper; Data::Dumper->Dump([$coderef],['coderef']); { my $file = 'hoho.txt'; $coderef->(); } } $sub = sub { print "$file.YYY" } x $sub;