# save all other slots of the typeglob foreach my $slot (qw( SCALAR ARRAY HASH IO FORMAT )) { my $elem = *{ $src->{$symbol} }{$slot}; next unless defined $elem; push @slots, $elem; } # clear out the source glob # undef &{ *{$src->{$symbol}} } didn't work undef $src->{$symbol}; # replace the sub in the source $src->{$symbol} = sub { logCall->($symbol, @_); return $sub->(@_); }; # replace the other slot elements foreach my $elem (@slots) { $src->{$symbol} = $elem; } }