in reply to how to make timeouts?

You can do this using the alarm function, and using a signal handler.
perldoc -f alarm