Okay, so this is a bit late. I'm just adding it because it's an obvious use of the range operator for extracting the data. Using some of the tomfoolery above but trying to match the specs as I understand them (no, not trying to golf):
use strict; use warnings; my $start_tag = qr/\*\*\* begin file \*\*\*/; my $end_tag = qr/\*\*\* end file \*\*\*/; my $case = ''; while ( <DATA> ) { # The range operator is sorely underused. if ( /$start_tag/ .. /$end_tag/ ) { if ( /$start_tag/ or /$end_tag/ ) { s/file/substituted file/; } else { $case = $_ & ' ' x length; s/old/NEW/i; } print $_ | $case; } } __DATA__ test *** begin file *** old_word OLD_WORD oLd_wOrd olD_worD *** end file *** test2
Prints:
*** begin substituted file *** new_word NEW_WORD nEw_wOrd neW_worD *** end substituted file ***

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to (Ovid - coming in late) Re: Substitute Question by Ovid
in thread Substitute Question by RiotTown

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.