use DBI; my $dbh = DBI->connect('dbi:ODBC:Data Source', 'username', 'password', {RaiseError => 1,}); my $sth = $dbh->prepare('SELECT customercode FROM customerorders WHERE ordercode = ?') or die "Couldn't prepare statement: " . $dbh->errstr; print "Enter ordercode> "; while ($ordercode = <>) { # Read input from the user my @data; chomp $ordercode; $sth->execute($ordercode) # Execute the query or die "Couldn't execute statement: " . $sth->errstr; # Read the matching records and print them out while (@data = $sth->fetchrow_array()) { my $customercode = $data[1]; my $ordercode = $data[2]; print "\t $customercode $ordercode\n";