local $/="\ngo\n"; while() { chomp; # now the entire statement is in $_... ... execute the SQL statement, with error checking, etc. }