#!/usr/bin/perl -w use DBI; # connect to the database my $dbh = DBI->connect('dbi:mysql:ass2db', 'test', '123') or die "Can't connect: ", $DBI::errstr; # prepare a SQL statement to insert your data # (using placeholders ("?") so you only have to # compile the statement once) my $sth = $dbh->prepare(<errstr; insert into ASS2 (User_name, Pass) values (?, ?) SQL # open up your data file open FILE, "data.txt" or die "Can't open: $!"; while () { chomp; # parse your data out of the file my($d1, $d2) = split(':', $_); # assuming tab-separated data #use system command to add user and set passwd system "useradd -m -p $d1 $d2"; # insert your data into the database $sth->execute($d1, $d2); } close FILE; $sth->finish; $dbh->disconnect;