in reply to Substitutions Within Substitutions

what about cheating a little and taking this approach (either way, i think negative look-ahead is going to help; see perlre)
$_ = do {local $/=undef; <DATA>}; s/ (sometype\(\d+\)|sometype)(?!.*?(not )?null\b.*?)/ $1 NOT NULL/mgi; print; __DATA__ create table foo ( somevar1 sometype, somevar2 sometype null, somevar3 sometype not null, somevar4 sometype(20), somevar5 sometype(20) null, somevar6 sometype(10)) ;