use DBI; my $dbh = DBI->connect( "DBI:mysql:database=test;host=localhost", "username", "password" ); my $sth = $dbh->prepare( 'select * from table_foo' ); $sth->execute(); my $numrecords = $sth->rows; my $numfields = $sth->{'NUM_OF_FIELDS'}; $sth->finish; print "I found $numrecords records, each having $numfields fields.\n";