in reply to Regarding the conditional part of eslif (or if) statement

You need an expression, something that can return a value. If you use something that doesn't return a value (like foreach), how could the elsif decide whether to enter or not? Your foreach doesn't even have a body, which makes even less sense.

elsif ($lec eq $outdate{$key1}) { foreach (@pmis) { if ($_ eq $outdate{$key1}) { ........ } } }