my $ary_ref = $sth->fetchall_arrayref(); if ($DBI::errstr) { print "Error detected: $DBI::errstr\n"; return; } else { if (ref($ary_ref) eq 'ARRAY') { # go on to process the array reference. } else { # do something with Data::Dumper } }