$. is a useful variable

(187 strokes) $. is the line number on input; serves the same function as our explicit state variable $PRINTED_LINE.
#!perl -nl
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]$/;
print;
END {
	$.&&maybe_print_m
}