You can do something similar to what you want with ulimit; you can limit your script to 30 seconds of CPU time (not wall-clock time) by running ulimit -t 30 before you start your script.
Comment on Re: brutally stop a perl program if it runs too long