foreach $byrank (@totalurl) { my $sth = $dbh->prepare(qq{ SELECT rank FROM indexed where url = '$byrank' }); $sth->execute(); while (my ($rank) = $sth->fetchrow_array()) { print "$rank\n"; } $sth->finish(); }