I have a form that the user is allowed to type plain text and/or HTML into. I need to recognize urls within this text that have not already been wrapped in an anchor <A HREF> tag, and then wrap them so they end up as hyperlinks. If already wrapped, I want to leave them alone.

I have an expression that does this for the whole string:

$myformtext =~ s!(http://[^\s]+)!<a href="$1">$1</a>!gi;
But can I somehow apply this only to the portion of the text that is not within an <A HREF> tag? Maybe split it or something? I'm not a perl expert...

20041011 Edit by ysth: add p and code tags

In reply to How to recognize url in text and convert to hyperlink, unless already in anchor by Anonymous Monk

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