sub some_event { my $cpp_obj = shift; # It's an arbitrary time later. We have no guaranty # the object is still around. return unless $cpp_obj; # I want this to work: if the underlying C++ object # is gone $cpp_obj should return undef in scalar context. # Do stuff that will blow up if $cpp_obj is gone. # ... } sub i_get_called_from_cpp_code { my ($cpp_obj, $time) = @_; my $event = sub { some_event($cpp_obj) }; Scheduler::new_event($time + 10, $event); }