my $sth = $db->prepare("SELECT foo, bar FROM Cust_ac_da WHERE CustomerID = ? AND #TranType= 'P'") or die "prepare failed: " . $db->errstr()."\n"; $sth->execute($CustomerNumber); while (my @stuff = $sth->fetchrow() ) { # do things with @stuff } $sth->finish;