package A; my $var = 1; sub mysub { print $var; } B::yoursub( \&mysub ); 1; #### package B; sub yoursub { shift->(); } #### #!/usr/bin/perl -w use strict; my $pid; my $output; defined( $pid = fork ) or die "Unable to fork!\n$!\n"; if ( $pid ) { print "Hi! I'm a parent! This is my child $pid\n"; while ( ( $output = kill( 0, $pid ) ) > 0 ) { print "I'm going to wait for my child to die...\n"; print $output, "\n"; sleep 2; } } else { print "I'm a kid! My name is $$\n"; print "I'm going to die now\n"; } #### #!/usr/bin/perl -w use strict; my $pid; my $output; defined( $pid = fork ) or die "Unable to fork!\n$!\n"; $SIG{CHLD} = 'IGNORE'; # this is the only difference if ( $pid ) { print "Hi! I'm a parent! This is my child $pid\n"; while ( ( $output = kill( 0, $pid ) ) > 0 ) { print "I'm going to wait for my child to die...\n"; print $output, "\n"; sleep 2; } } else { print "I'm a kid! My name is $$\n"; print "I'm going to die now\n"; } #### #!/usr/bin/perl -w use strict; my $input = qq( After first style After first style