in reply to Re: undefing *foo{CODE} does not fully work
in thread undefing *foo{CODE} does not fully work

While that and works, it also undefines @foo, %foo, etc. It seems to me that the OP is trying to undefined &foo specifically.

Other working solutions with the same caveat:

my $x = \*foo; undef *$x;

and

my $x = 'foo'; { no strict 'refs'; undef *$x; }

and

my $x = do { no strict 'refs'; \*{'foo'} }; undef *$x;