package Reduce; use strict; use warnings; sub import { my $caller = caller; no strict 'refs'; *{"$caller\::reduce"} = \&reduce; } sub reduce (&@) { my $code = shift; my $caller = caller; my $x; my $z; no strict 'refs'; local(*{"$caller\::a"}) = sub { $x }; local(*{"$caller\::b"}) = sub { $z }; $x = shift; for (@_) { $z = $_; $x = &{$code}(); warn $z; } $x; } 1; use strict; use warnings; use Reduce