my $count = $sth->execute; if (! $count) { die "Couldn't execute >>$sql<< : " . $sth->errstr; }; if ($count == 0) { print "No rows were affected."; } else { while (my $pointer = $sth->fetchrow_hashref) { ... do magic ... }; };