in reply to variable flags to match operator?
You probably want to use the embedded form (?ismx:foo), which you could whip up on the fly using the qr// operator. Search for `imsx-imsx:pattern' in perldoc perlre for more info.