my @sorted = sort grep /^[a-z](?:[^-]|-(?!-))*(?<=[a-z])$/i, @words; #### /^[a-z] # Start with a letter. (?: # Start grouping. [^-] # Anything other than a hyphen | # Or -(?!-) # A hyphen not followed by another hyphen )* # End group. Match 0 or more of those groups. (?<=[a-z])$ # The end, as long as it is preceded by a letter. /ix # Match case insensitively and allow comments. #### /^[a-z](?:[^-]|-(?!-))*[a-z]$/i