You should be using exceptions. Read up on the block form of eval.

In reply to Re: Idomatic Handling of Subroutine Error by perrin
in thread Idomatic Handling of Subroutine Error by dvergin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":