my $d = *{ 'main::destination::' }; delete $d->{foo}; #### *FOO = sub { print "SUB FOO OK!\n" } ; $FOO = 123 ; print ">>>>>>>>>> BEFORE RM:\n" ; eval{ FOO() } ; warn($@) if $@ ; print "CODE: " . *FOO{CODE} . "\n" ; print "SCALAR: $FOO\n" ; glob_rm( \*FOO , 'CODE' ) ; print ">>>>>>>>>> AFTER RM:\n" ; eval{ FOO() } ; warn($@) if $@ ; print "CODE: " . *FOO{CODE} . "\n" ; print "SCALAR: $FOO\n" ; sub glob_rm { my $glob = shift ; my $type = uc( shift(@_) ) ; my %holder ; foreach my $tp ( qw(SCALAR ARRAY HASH CODE IO FORMAT) ) { $holder{$tp} = *{$glob}{$tp} if $tp ne $type ; } if ($type eq 'SCALAR') { undef ${*{$glob}} ;} elsif ($type eq 'ARRAY') { undef @{*{$glob}} ;} elsif ($type eq 'HASH') { undef %{*{$glob}} ;} elsif ($type eq 'CODE') { undef &{*{$glob}} ;} elsif ($type eq 'IO') { close *{$glob} ;} undef *{$glob} ; foreach my $Key ( keys %holder ) { *{$glob} = $holder{$Key} ;} } #### >>>>>>>>>> BEFORE RM: SUB FOO OK! CODE: CODE(0x1a72bac) SCALAR: 123 >>>>>>>>>> AFTER RM: Undefined subroutine &main::FOO called at tmp.pl line 17. CODE: SCALAR: 123