In theory, you can't edit directly a sequential file. You would need to read the input file, preferably line by line, edit the lines and write them to another file, and either before or after that, do the file renaming if needed (another option is to read the input file into memory, do the changes into memory, close the file and then reopen it in write mode, which will erase everything in the file, and write the stored lines into the newly created file, but this other option may not be used if your file is so big that it will not fit in memory).

So you would need something like this:

# ... open my $in, "<", "uuu.txt" or die "cannot open the input file$!"; open my $out, ">", "out.txt" or die "cannot open the output file$!"; while (my $line = <$in>) { $line =~s/[\s\d]//g; print $out "$line\n"; } close $_ for ($in, $out); # ... renaming, etc.
However, this being Perl, you have some command line options which will do the boiler plate code (opening and closing the files, reading input line by line, and file renaming) for you behind the scene, so that this one-liner (or the almost identical one proposed by vinoth.ree) will do everything for you:
perl -i.bak -p -e 's/[0-9\s]//g' uuu.txt

In reply to Re: Removing white space from the file by Laurent_R
in thread Removing white space from the file by GSperlbio

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.