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.
Comment on Re: Regular Expression: Matching arbitrary characters
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.