use strict; use warnings; use MCE::Shared; package My::String; sub new { my ($class) = @_; my $string = MCE::Shared->scalar($_[1]); return bless [ $string ], $class; } sub set { my ($self) = @_; $self->[0]->set($_[1]); return 1; } sub get { my ($self) = @_; return $self->[0]->get(); } package main; my $string = My::String->new("First value"); sub do_subroutine { print "I am the subroutine and my PID is $$\n"; $string->set("Second value"); } print "I am the invoking process and my PID is $$\n"; print "The value of \$string is ", $string->get(), "\n"; unless (fork) { do_subroutine (); exit; } my $waited_pid = wait; print "The PID of the child upon whom I waited was $waited_pid\n"; print "The value of \$string is ", $string->get(), "\n"; __END__ I am the invoking process and my PID is 23089 The value of $string is First value I am the subroutine and my PID is 23091 The PID of the child upon whom I waited was 23091 The value of $string is Second value