while (my @array = $sth->fetchrow_array()){ print ""; foreach my $elem (@array){ #search & display the first element in the array for the regex $searchTitle=$array[0]; if ($searchTitle=~/(?=.*pr\w{4}m)(?=(?=\w*w\w*)(?=\w*b\w*)\w+\b)/){ print ""; print "$elem\n"; print ""; #SAVE OUTPUT FOR SEARCH 3: #WARNING: This prints out the title element n times where n = number # of columns in the SQL search unless (open (LOGFILE, ">>//applications/mamp/logs/search1results")) {print "Failed to open search1results log!";exit} flock (LOGFILE, LOCK_EX); print LOGFILE "$searchTitle\n"; unless (close (LOGFILE)) {print "Failed to close search1results log!";exit} } } }