my $t1_count = table_row_count( $dbh, 'table1' ); my $t2_count = table_row_count( $dbh, 'table2' ); sub table_row_count { my $db = shift; my $table = shift; my $sth = $db->prepare_cached( "select count(*) from $table" ); $sth->execute(); return $sth->fetchrow_array; }