#!/usr/bin/perl use DBI; $|=1; my $dbh = DBI->connect('DBI:mysql:foodb:localhost', 'user', 'pass'); my $sth = $dbh->prepare("SELECT a FROM table WHERE b = ?"); my $b; while (my $a = ) { chomp $a; $sth->execute($a); $sth->bind_columns(\$b); $sth->fetch; print "$b\n"; }