If changing $0 doesn't work as
merlyn suggests, you can try using
pipe to create read/write filehandles before the
fork. See
Collecting pids from children, their children, etc. (aka: pipeline of system(@list) calls) for somewhat of an example (update: nevermind, just see
perlipc), though that example execs several levels deep, and does stuff you don't need to do, like redirecting STDIN from the child. Just write line numbers instead of the pids from the child.
Updated.