@to_check=('bat','bbat','brat'); for (@to_check){ if (/^([bat])(?!\1)([bat])(?!\2)([bat])(?!\3)/){ # do something } }