in reply to detection in Loop condition

You are running a substitution regex (a very complex one at that) $line =~ s/.../MISSING/ upon $line, but I don't see a substitution in this regex.

You need to simplify the problem - the code that you have makes no sense.