Please see perlfaq5:
How can I use Perl's "-i" option from within a program? "-i" sets the value of Perl's $^I variable, which in turn affec +ts the behavior of "<>"; see perlrun for more details. By modifying +the appropriate variables directly, you can get the same behavior within a larger program +. For example: # ... { local($^I, @ARGV) = ('.orig', glob("*.c")); while (<>) { if ($. == 1) { print "This line should appear at the top of eac +h file\n"; } s/\b(p)earl\b/${1}erl/i; # Correct typos, pre +serving case print; close ARGV if eof; # Reset $. } } # $^I and @ARGV return to their old values here This block modifies all the ".c" files in the current directory +, leaving a backup of the original data from each file in a new ".c.o +rig" file.

That is one approach, using <> by setting @ARGV. If you simply wish to work on another filehandle, look at the first question in perlfaq5 ("How do I flush/unbuffer an output filehandle? Why must I do this?"), where it states how to set per-filehandle variables (like $| and our desired variable $^I):

# Long, understandable version $old_fh = select(OUTPUT_HANDLE); $^I = '.orig'; select($old_fh); # Short version $^I = '.orig', select $_ for select OUTPUT_HANDLE;
or if you wish to keep the new OUTPUT_HANDLE selected, simply select( OUTPUT_HANDLE ); $^I = '.orig'; Good luck!

Update: Trying to actually answer the question.

In reply to Re: Inplace file edit mark II by kaif
in thread Inplace file edit mark II by GrandFather

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.