package MyModule; use File::Rsync; my $rsync; { my %rsync_out; $rsync=File::Rsync->new( { outfun => &rsync_out, errfun => &rsync_out, } ); sub rsync_out { my ($message, $type)=shift; $rsync_out{$type}.="$message\n"; } sub outmsg { $rsync_out{out} } sub errmsg { $rsync_out{err} } } # ... # code here has no clue about %rsync_out # (but it can still see $rsync because I declared # it outside the braces.) # ... # Access the output using the outmsg and errmsg subs my $output = outmsg;