use Exception::Class ( SomethingException => { fields => [qw/error_code error_msg/] }, ); .... much later if ($this_is_not_right) { SomethingException->throw( error_code => 123, error_msg => 'this is error' ); }