I think I figured it out:
$sql =~ s{ (create\s+table\s+\w+\s*\() # "create table foo (", save as $1 ( # Save all the elements as $2 ( # Grab this pattern (each of the c +reate table variables), save as $3 \s* # Any spaces \w+ # Variable name \s+ # At least one space \w+ # Variable type ( # Optional (nnn) for character str +ing types, save as $4 \( # Literal open paren \d+ # Any number of digits \) # Literal close paren )? # The ? makes it optional \s* # Any spaces [\w\s]* # Any words and/or spaces ("null" +or "not null", specifically) ,? # Optional comma (optional as it m +ay be the last element) \s* # Any spaces )+ # Match this whole section at leas +t once ) (\s*\)\s*) # Closing paren for create table b +lock with surrounding whitespace, save as $5 } { @elements = split(/,/, $2); foreach $elem (@elements) { if ($elem =~ /null\s*$/i) { next; } $elem .= " NOT NULL"; } $1 . (join ",", @elements) . $5 }gex;
I changed the regex to grab the whole block of table elements (getting rid of some unnecessary parens in the process), then just did an easy split and join on them inside the right hand block. Then I switched the prints to a concatenation so it would actually do a substitution.

---
A fair fight is a sign of poor planning.


In reply to Re: Substitutions Within Substitutions by Sprad
in thread Substitutions Within Substitutions by Sprad

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.