use DBI; use FindBin; use File::Spec; use IO::File; my $insert_sql = "some SQL statement"; my $dbh = DBI->connect( 'dbi:Mysql:database=some_db;host=some_host', 'user', 'password', { PrintError => 0, RaiseError => 1, }) or die "Cannot connect\n"; my $sth = $dbh->prepare( $insert_sql ); my $fh = IO::File->new( File::Spec->catfile( $FindBin::Bin, 'some_file.txt' ) ) or die "Cannot open file"; scalar(<$fh>) for 1 .. 2; while ( my $line = <$fh> ) { chomp $line; my @fields = map { s/"//g; s/^\s+//; s/\s$//; $_ } split ',', $line; $fields[5] = (2 - $fields[5]) + 1; $sth->execute( @fields[1..4], @fields[4..5], 0, 0 ); } $sth->finish; $dbh->disconnect;