my $sub_str = q{ sub { my $n = shift; return $n + 1; } }; # send the string through the socket # at the far end of the socket: my $sub_ref = eval $sub_str; print $sub_ref->(2), "\n";