#!/usr/bin/perl use warnings; use strict; use DBI; use Fcntl qw/:flock/; my $dbh = DBI->connect('DBI:mysql:database=fruits;host=localhost', 'Admin', 'pass', {'RaiseError' => 1}) or die $DBI::errstr; my $query = qq~INSERT INTO table_name (name, count, color, weight) VALUES (?, ?, ?, ?)~; my $sth = $dbh->prepare($query); open DATA, "sample.txt"; flock DATA, LOCK_EX; while ( ) { chomp; $sth->execute(split /\|/); } close DATA;