my $row1 = fetch_count($dbh, "table_one"); my $row2 = fetch_count($dbh, "table_two"); print "$row1, $row2\n"; sub fetch_count { my $dbh = shift; my $table = shift; my $sth = $dbh->prepare("select count(*) from $table"); $sth->execute; my $row = $sth->fetch_arrayref; return $row->[0]; }