$patient = "Alex"; $new_doc = "Kessler"; open (REC, "record.data"); @data = ; close (REC); foreach $line (@data) { my ($id, $patient, $room, $doc) = split (/!/, $line); if (($patient =~ /($new_patient)/i) && ($doc =~ $new_doc)) { print "$line\n"; } else { print "NO PATIENT BY THAT NAME\n"; }