sub work { my $something_wrong = 1; if( $something_wrong ){ #return Error->new(0, "because ..."); return bless [0, "because ..."] => 'Error' } # edit: changed to a hashref to show returning different types # it need not be a ref at all, e.g. can send a hash too #return [1,2,3] return {1=>2, 3=>4} } my $ret = work(); if( ref($ret) eq 'Error' ){ die "error: @$ret" } print "got some results:".Dumper($ret);