Solution 

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