Solution 

#!/usr/bin/perl -nl
($a, $b) = split /\./;
$h{"$a.$b"} = 1;
$h{"$a.M"} = 1;
END { print join("\n", sort keys %h); }