in reply to Need regular expression

You "need" to help yourself. Read Markup in the Monastery AND perldoc perlretut and perldoc perlre. This is NOT code-a-matic -- even when you post unintelligible nonsense.

Please format each code, data and sample output within a SEPARATE <c> </c> (code) block to make your question easy to understand.

Your attempt at substitution is

  1. wrong
  2. un-neccessarily complex
  3. incomplete (post compileable code; show how you're populating $string).

UPDATE: Fixed borked codetag example. TY, MLX!