in reply to How to know if a perl script is put in the background
Don't forget to handle the edge case where a process can move back and forth between the foreground and background. eg, start your process in the foreground, press C-z to stop it, type 'bg' to background it, type 'fg' to foreground it again, and so on.