use strict; use warnings; open tempFile, '>', "test.dat"; print tempFile <; # Open the file/s to remove these matches from open CURRENTDAT, '<', "test.dat"; my @DatLines = ; # For each line in the file to match from for ($a = 0; $a < scalar(@DatLines); $a++) { # Go through each line of the file to remove these matches from for (my $i = 0; $i < scalar(@BadShares); $i++) { # If the current line in the DAT matches any line in the file to match set # that line to zero if ($DatLines[$a] =~ m/(\Q$BadShares[$i]\E)/i) { print "MATCH $DatLines[$a] $BadShares[$i]"; } } } __DATA__ Line 8 is the last line in the file test.dat (this error changes if I add lines it is always the last line). Line 23 is the pattern match part of the code. If I print the lines as it goes it is less than half way through Bad_Shares.TXT and the line changes as I add lines to test.dat (running out of memory?). This is my early test script before I get it to go through a list of files in a given directory (lots of DATs containing drives to map for specific users).