my @lines = read_file('/tmp/test.txt'); chomp(@lines); my $sql = q|select * from table_name where srcaddr = ? or dstaddr = ?; foreach my $line (@lines) { $sth->execute($line, $line) or die "Can't execute SQL statement: $DBI::errstr\n"; my @all_rows; while (($line) = $sth->fetchrow_array()) { push(@all_rows, $line); } foreach (@all_rows) { print "$_\n"; } }