http://www.perlmonks.org?node_id=108529


in reply to Let's get lazy

If memory use is your only concern, then here's a rehash (har har har) of one of my prior atrocities...
  
$_ = 'acgnt' x 4; push @strings, "$1$2" while /.*(.).*(.)(?(?{$_{"$1$2"}++})^)/; push @strings, "$1$2$3" while /.*(.).*(.).*(.)(?(?{$_{"$1$2$3"}++})^ +)/; push @strings, "$1$2$3$4" while /.*(.).*(.).*(.).*(.)(?(?{$_{"$1$2$3$4 +"}++})^)/; print join $/, @strings;
   MeowChow                                   
               s aamecha.s a..a\u$&owag.print