while () { my $a = join('', sort split //, $_); my @a = $a =~ /((\d)\2+)/g; print "$_" if grep {length $_ == 2} @a; }