m{ ^ # start of the string FOO ( # this will become $1 (?! # must not be BA[RZ]$ # BAR or BAZ followed by end-of-string ) .* # now anything else (except "\n") # no need to "$", because ".*" will happily swallow it all ) }x