Ooops, still have "print".

(180 strokes) When golfing, explicit mention of print is almost always a mistake.
#!perl -pl
sub maybe_print_m {
	$DONE_M || print "$PREFIX.M";
}
/$PREFIX/ or$DONE_M=!maybe_print_m;
/\./;
$PREFIX=$`;
$DONE_M=/M$/ || maybe_print_m if /[M-Z]$/;
END {
	$.&&maybe_print_m
}