my @test = qw/xyzabcxxx xyzaabxxx xyzabbxxx xyzabaxxx/; for (@test) { # only check for 'abc' say if not /([abc]).*?\1/; }