in reply to Restarting counters in text

if ($_ != /<exm>/g)

You need to go back and have another read of perlop.

You're saying "if $_ isn't numerically equal to the value returned when you try to match /<exm>/ against $_". What you're trying to say is "if $_ doesn't match /<exm>/". That's written as:

if ($_ !~ /<exm>/)

or (perhaps easier to understand)

if (!/<exm>/)

When all else fails, it's always worth reading the documentation for the syntax you're trying to use :-)

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg