sub requestDB { ... if ($some_error) { return "This error occurred: $DBI::errstr"; } return \@results; # reference to results array } my $a = requestDB(...); if ( ! ref $a ) { # if $a is not a reference, it's a scalar that holds the error message die $a; } elsif (@$a) { # if @$a is nonzero, there were results ... } else { # there weren't results print "No results found, sorry!" }