#!/usr/bin/perl use strict; use warnings; sub foo { my $sub = shift; local $_; $sub->(); } $_ = 10; foo (sub { print $_ });