The script you posted is working perfectly fine. There must be a problem with the actual input you are using. That being said there's quite a lot you could do to improve the RegExp:

((\w|\s)+) is better written as a character class, e.g.: ([\w\s]+)

Are you sure this is what you want? According to W3C there are no HTML-colors with whitespace in their name.
Use \s*(\w+)\s* instead? Additionally you fail to match valid colors like #ff0000

("|')? .... ("|')? -> would match "abc'; better use a back-reference: (["']?) .... \1

<\/font> can be replaced with </font> since you are using s~~~ instead of s///

\[color=$2\]$5\[/color\] can be converted into [color=$2]$5\[/color] (must keep the escape after $5 or perl complains)

Additionally: I don't know where the input is coming from and how you much you can trust it. Your code 'fails open' - nothing happens in case it fails to match. I would suggest to convert it into 'fail closed' - complain loudly or even terminate in case a font tag can not be matched propely.

while (parse input) {
  if (a font tag is found)) {
    if (font tag matches expected pattern) {
      (replace font tag)
    }
    else {
      (complain loudly)
    }
  }
}

In reply to Re: Regex not working by Monk::Thomas
in thread Regex not working by Beaker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.