BillKSmith is correct. Try:
perl -i.bak -p -e "s/gary/harry/g;" file.txt
Otherwise, you should really read the documentation, but these are quick answers to your question. The command line switches say:
-i
Inline editing, i.e. the file itself is modified (but, yes, there is some file renaming behind the scene);
-p
Assumes an input loop around the script to read all lines of the original file and print back the modified lines.
-e
the text coming between the quotes after this switch is to be taken as the Perl script to be executed (the more common usage, without the -e switch, is to put there name of the file containing the script.

s/source/target/ is the substitution operator. It replaces source with target. In this specific case, the substitution is applied to the string contained in the default $_ variable, which contains successively each line of the input file. The g modifier says that this substitution should be made as many times as possible (i.e. for all occurrences of source in the current string).

This was just a very quick answer to your questions (too short to be entirely accurate, but at least you should get the idea), there would much more to say, but go for the documentation you have been pointed to by other monks.

In reply to Re: Text not being replaced in file via Windows CLI ... by Laurent_R
in thread Text not being replaced in file via Windows CLI ... by perlynoob

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.