in reply to regular expression issue

Do you really want to do regular expression matching?

if ((lc $patient eq lc $new_patient && lc $doc eq lc $new_doc) {
will give you a match only when there is an exact match (which appears to be what you're asking for).

Otherwise you're going to have to ask for more information: if the patient's name is Simon, does this match the existing Simons, or is it a new one? With a regexp, it's an existing patient; with equality, a new one. You've got the same problem with the two Simons in your example.

--
Tommy
Too stupid to live.
Too stubborn to die.