You search for a backslash in the second alternative, that should be a forward slash. Anyway, that latter alternative is useless, as the former one will match it too. And like
castaway said, you're suffering from regexp greediness.
Your remaining problems are:
- A tag can contain "<" or ">" characters in quoted attributes
- a tag can contain a newline. Why read line by line anyway?
To solve the first problem, you could try the next:
s/<(?>[^>'"]+|"[^"]*"|'[^']*')*>//g;
Try it with
$_ = '<foo attr="heh>hoh">bar</foo>';
As for the second problem, processing the whole file in one go while adding the /s modifier, would probably help.