$dbh=DBI->connect('DBI:mysql:genome', 'u', 'p'); $sth = $dbh->prepare ("SELECT P.gene_name_M FROM para_n P WHERE P.number_genes_group = 4"); $sth->execute () while (@ary = $sth->fetchrow_array ()) { foreach (@ary) { #...........rest of code