Assume your database is setup in a state where you would expect connections to fail, you might be suffering from buffering - your prints have no newlines at the end so the messages are sitting in a buffer waiting to be output. Try adding newlines or setting $| to a positive integer, and see what results you get.