Getting specific --#-- Now that we have the names of only text input fields, we can pick out just those <input tags and not worry about the type parameter.

$val = $query->param($_); $html_content =~ s/(]*)name="?$_"?)([^>]*>)/$1 $2 value="$val" $3/si;
This regex uses an easy, but handy, trick for matching most characters inside the <input> tag: [^>]* This means zero or more characters that are anything but NOT the tag closing character $gt;. In regexes, it's often -- though not always -- easier to say what you're NOT looking for. Here, it doesn't matter what comes between the <input beginning and the name parameter, as long as it's not the close of the whole <input> tag.

Surprise! This substitution actually works pretty well. But what happens if the user enters unusual characters into the field. As it turns out, the worst he can do is put quote marks in -- Mack "the knife" O'Shaugnessy.
Try this with this regex. The browser, when it redisplays the field, will display only Mack. You could get around this by surrounding the value characters with a single quote instead of a double quote mark. But what if he uses a single-quote for an apostrophe: Mack "Momma's Boy" O'Shaugnessy. Catastrophe!

As it turns out, there's a simple solution: URL-encode the double quotes:

$val =~ s/"/"/g;
This gives us a very robust set of code for finding and stuffing in all the text fields:

@texttypes = getTexts($html_content); foreach (@texttypes) { $val = $query->param($_); $val =~ s/"/"/g; $html_content =~ s/(]*)(name="?$_"?)([^>]*>)/$1 $2 value="$val" $3/is; } sub getTexts { my($html) = @_; my @t = (); my @texts = split(/