sub name { { package For_name_internal_use; use overload '""' => sub { $_[0]->() }, fallback => 1; } return bless sub { my $in_copy; for (my $stack = 2; ! $in_copy and my @caller = caller($stack); ++$stack) { $in_copy = 1 if $caller[3] && $caller[3] eq 'whatever::copy'; } if ($in_copy) { return 'some result to be used in whatever::copy'; } else { return 'some result to be used outside of whatever::copy'; } }, 'For_name_internal_use'; }