Without looking in detail, what is obvious is that your perl process sends a hang-up signal to itself (SIGHUP). There is no handler set up for this signal, so the process is killed. So the problem is either that the process shouldn't be sending itself a HUP signal, or that you need to handle it.