(bar.+?qux)|(foo) # capture anything with 'bar' and 'foo' as # bookends in $1 OR # all other 'foo' in $2 defined $2 ? '123' : $1 # if $2 exists, replace it with 123 # otherwise replace $1 back into # the string ]ge # eval globally