sub import { # two loops because we don't want to splice @_ while looping over it if ( grep { /:(?:bar|baz)/ } @_ ) { my $sub = caller(0) . '::set'; { no strict 'refs'; *{$sub} = \&set; } } # using goto to avoid updating caller goto &Foo::import; }