in reply to parsing long text file

You might also try adding the 'o' option to the replacements, this tells the Perl interpretor to only 'compile' the regular expression once and not on each time through the loop. Example:
if( m/iapw_p1/ ) { s/iapwp1/$p1/og; print; }

-----------------------------------
Frank Wiles <frank@wiles.org>
http://frank.wiles.org