foreach my $line (@lines) { $sth->execute($line, $line) or die "Can't execute SQL statement: $DBI::errstr\n"; my @all_rows; while ( my $ref = $sth->fetchrow_arrayref()) { push(@all_rows, $ref); } foreach my $row_ref (@all_rows) { print "@{$row_ref}\n"; } }