$_ = 'foo... ... '; if (m{^(?: . (?! .*? foo ))* }sx){ print "Match\n"; } # match