my $dbh = DBI->connect(@db_args); my $sql = "SELECT email FROM database.table"; my $sth = $dbh->prepare($sql); $sth->execute(); while (my $hashref = $sth->fetchrow_hashref) { ...