You don't have to specify the global flag. From the documentation, there is a separate parameter ($limit) used to specify the number of replacements to make:
limit
The maximum possible replacements for each pattern in each subject string. Defaults to -1 (no limit).
So, unless you specify a positive number for this parameter, it will replace all occurrences by default: