$test = "/lawyers/c~p~~carmel~family~divorce~lds~y~firms.html"; if ($test =~ /(\/lawyers\/)(.*)(?!LDS)(.*)(\~Firms\.html)+/i ){ print "matched\n"; }