in reply to a way to do 'sort|uniq'

If the Perl equivalent of a shell one-liner is 6 lines, I'd use system to shell out.

However, your Perl version isn't equivalent - it's removing anything that's not a number (s/[\D\n]//g contains many hooks to improvement - I'd write it as tr/0-9//cd or if you insist on a substitution: s/[\D]+//g).

If I were to do it in Perl, I'd remove the duplicates first (using a hash), then sort. If there are a lot of duplicates, this ought to win (although in modern Perls, sorting with many duplicates is fast).