Solution 

#!/usr/bin/perl -nlp
/\./;
@h{$_,"$`.M"}=1;
}$_=join($\, sort keys %h);{