# This code assumes that you've already initialized a # database handle, $dbh, and your string of data is in # $input my $sth = $dbh->prepare('INSERT INTO my_table (field1, field2, field3) VALUES (?, ?, ?);'); my @records = split '&', $input; foreach my $record (@records) { my @fields = split '\|', $record; $sth->execute(@fields); }