How about print "M$End\n"; after the for loop? And note you talk about an array but your code doesn't include one (for output, that is), but I assume you'd probably want to push elements onto a new array instead of printing them.
BTW, your regexes for getting the numbers from the input aren't quite right, the + quantifier needs to be inside the capture group, and since you're already using regexes, you can use them for validation too. For example, my ($num_1) = $input1 =~ m/^m(\d+)$/i or die "bad input: $input1";
A few edits shortly after posting.