#=========== INSERTING MULTIPLE FILENAMES & CONTENTS INTO DATABASE ============= my $data; my $insert = $db->prepare( 'INSERT INTO articles (title, body) VALUES (?, ?)' ); my @files = glob "$ENV{'DOCUMENT_ROOT'}/data/text/*.txt"; foreach (@files) { open FILE, "$_" or die $!; $_ = map m{([^/]+)\.txt}, $_; #Strip out of the string th path and extension leaving only the filename intact $data = ; #Grab the whole file contents at once $insert->execute($_, $data) or print $db->errstr; close FILE; }