if($sorted_values=~/(([abcdefghijklm])\2)/){ # Rest of code here }