As tantarbobus as mentioned already, you can't have a count of rows beforehand with MySQL, unless you make sure you are using mysql_store_result (which is the default mode with DBD::mysql, BTW).
In PHP it's the same story. PHP is hiding complexity from you. If the method mysql_num_rows() works, it's only because PHP uses always mysql_store_result(). If you read the relevant explanation on MySQL manual you'll see that a count of rows is only possible after you are finished fetching them.
That said, If you want to be sure of the row number and you don't want to use a separate COUNT(*), then the only way is to use one of the "fetchall_*" or "selectall_*" methods from the DBI.
my $sth = $dbh->prepare($sql);
$sth->execute || $error->LogError("whatever ".$dbh->errstr, 0);
my $recs = $sth->fetchall_arrayref;
my $count = @$recs;
Once you have the records stored in an array, the number of records is given, as for any array in Perl, testing the array in scalar context.