package Foo; use strict; use warnings; sub new { bless {}, shift; } sub DESTROY { warn "$$: destroy"; system("waaaah"); } package main; use strict; use warnings; use POSIX ":sys_wait_h"; my $foo = Foo->new(); my $pid = fork(); die "fork failed" if !defined $pid; if( $pid ) { # parent print "$$: parent\n"; } else { # child print "$$: child\n"; # system("waaaah"); exit 5; } my $reaped = waitpid($pid, 0); my $child_exit_status = POSIX::WEXITSTATUS($?); print "pid=$reaped status: $child_exit_status\n";