#=========== 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; } #### foreach (@files) { open FILE, "$_" or die $!; print "$_", br() x3; $_ = map m{([^/]+)\.txt}, $_; #Strip out of the string the path and extension leaving only the filename intact print "$_", br() x3; $data = ; #Grab the whole file contents at once print "$data"; exit; close FILE; }