You can't use the rows method on select statements, only on statements that modify the database. In those cases, for most DBDs $dbh->do($sql) returns the number of rows affected. In other words, you can't use rows to count the rows from a select statement. This is in perldoc DBI in some detail, under the ->rows method.