use warnings; use strict; sub foo { my $bar = shift; print "original foo($bar)\n"; } if (my $pid = fork()) { close PARENT; foo('parent'); close CHILD; waitpid($pid, 0); } else { die "cannot fork: $!" unless defined $pid; close CHILD; # overload the function no warnings 'redefine'; sub foo { my $bar = shift; print "modified foo($bar)\n"; } foo('child'); close PARENT; exit(0); } foo('the end');