in reply to Regular Expression: Matching arbitrary characters

In addition to what everyone else has said, I would also like to note that you are using $line =~ s/...//, which is a substitution. That's not what you want. You want to use $line =~ m/.../g. The /g modifier is used for global matching, which means on each iteration of the loop, it will save the current position in the string and match from there on the next iteration.

Replies are listed 'Best First'.
Re^2: Regular Expression: Matching arbitrary characters
by graff (Chancellor) on Dec 02, 2008 at 03:24 UTC
    Actually, the OP's use of the s/// operator is a perfectly legitimate and sensible approach, assuming that there's no problem with obliterating the input string as you go. As you point out, using m//g is also a good approach.