/ (?(?<=(.)) # We are not at the start of the string. # The preceding character is in $1. hello (?(?{ $1 eq "\{" }) # The char before 'hello' is '{'. } | # The char before 'hello' is not '{'. (?! } ) ) | # We are at the start of the string. hello (?! } ) ) /x