in reply to s/PATTERN/func()/em leaks /m into func()
Interesting! Did you try with (?imsx-imsx:pattern)? See perldoc perlre for more info.