#!/usr/bin/perl -w use strict; use DBI; my $dbh = DBI->connect('DBI:mysql:genome', 'u', 'p') || die $DBI::errstr; my $sth = $dbh->prepare("SELECT foo FROM bar WHERE baz = 4"); $sth->execute() || die $DBI::errstr; while (my ($foo) = $sth->fetchrow()) { # Do something with $foo eg: print "foo = $foo\n"; } $sth->finish(); $dbh->disconnect() || warn $DBI::errstr;