in reply to regex question

Without the "g", it becomes a boolean function, returning true or false. See perlretut for details and examples.

Read it too fast -- you are grouping properly, but I think you've got a typo. How about replacing $line with $string?

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.