The only thing you can "return" from a child process is an exit code, which is simply the value sent from your
exit call, but even then, you have to match this number up with the process in your signal handler, and so forth, so it's not very practical at all.
You will certainly want to read the
perlipc documents, those that deal with Inter-Process Communication. This is a fairly in-depth document, which can be confusing, but there are some good examples.
Since the parent and the child are separate processes, they can't communicate with eachother through variables, like you can within a single program. Instead, you have to create some sort of mechanism for communication explicitly.
Generally, this involves creating a
pipe that is shared the parent and child. This data conduit is used by the child to send any required data back to the parent.
Basically, the parent creates a
pipe, which is double-ended, and then forks. The child will use one end of the pipe to report, and the parent will use the other end to listen. It's kind of like a tin-can and string telephone.
Of course, the parent must check on these sockets for each child that is active. You can use
select, or, if you're feeling rather spirited,
IO::Select may be more to your liking since it is simpler. The idea is that while each child has a single end, the parent is going to have a whole lot of ends to check on, as data could come in at any time.
IO::Select will let you know when something comes in on one of them.
There is a good example of creating the pipe in the section of
perlipc entitled "Bidirectional Communication with Yourself".
There
A simpler approach, which is more of a hack, really, is to just save some data in a temp file (i.e. "/tmp/$$.progname") and have the parent pick it up when the child is done. I would certainly have a go with the pipes before taking these comparatively drastic measures, though.