perl(1) -F -l -anpeE -i -0 -M
how to execute the Perl interpreter
-Fpattern
     specifies the pattern to split on if -a is also in effect.  The pattern may be surrounded by "//",
     "", or '', otherwise it will be put in single quotes. You can't use literal whitespace in the
     pattern.
-l[octnum]
     enables automatic line-ending processing.  It has two separate effects.  First, it automatically
     chomps $/ (the input record separator) when used with -n or -p.  Second, it assigns "$\" (the output
     record separator) to have the value of octnum so that any print statements will have that separator
     added back on.  If octnum is omitted, sets "$\" to the current value of $/.  For instance, to trim
     lines to 80 columns:

         perl -lpe 'substr($_, 80) = ""'

     Note that the assignment "$\ = $/" is done when the switch is processed, so the input record
     separator can be different than the output record separator if the -l switch is followed by a -0
     switch:

         gnufind / -print0 | perl -ln0e 'print "found $_" if -p'

     This sets "$\" to newline and then sets $/ to the null character.
-a   turns on autosplit mode when used with a -n or -p.  An implicit split command to the @F array is
     done as the first thing inside the implicit while loop produced by the -n or -p.

         perl -ane 'print pop(@F), "\n";'

     is equivalent to

         while (<>) {
             @F = split(' ');
             print pop(@F), "\n";
         }

     An alternate delimiter may be specified using -F.
-n   causes Perl to assume the following loop around your program, which makes it iterate over filename
     arguments somewhat like sed -n or awk:

              LINE:
                while (<>) {
                    ...             # your program goes here
                }

            Note that the lines are not printed by default.  See -p to have lines printed.  If a file named by
            an argument cannot be opened for some reason, Perl warns you about it and moves on to the next file.

            Also note that "<>" passes command line arguments to "open" in perlfunc, which doesn't necessarily
            interpret them as file names.  See  perlop for possible security implications.

            Here is an efficient way to delete all files that haven't been modified for at least a week:

                find . -mtime +7 -print | perl -nle unlink

            This is faster than using the -exec switch of find because you don't have to start a process on
            every filename found.  It does suffer from the bug of mishandling newlines in pathnames, which you
            can fix if you follow the example under -0.

            "BEGIN" and "END" blocks may be used to capture control before or after the implicit program loop,
            just as in awk.
-p   causes Perl to assume the following loop around your program, which makes it iterate over filename
     arguments somewhat like sed:

       LINE:
         while (<>) {
             ...             # your program goes here
         } continue {
             print or die "-p destination: $!\n";
         }

     If a file named by an argument cannot be opened for some reason, Perl warns you about it, and moves
     on to the next file.  Note that the lines are printed automatically.  An error occurring during
     printing is treated as fatal.  To suppress printing use the -n switch.  A -p overrides a -n switch.

     "BEGIN" and "END" blocks may be used to capture control before or after the implicit loop, just as
     in awk.
-e commandline
     may be used to enter one line of program.  If -e is given, Perl will not look for a filename in the
     argument list.  Multiple -e commands may be given to build up a multi-line script.  Make sure to use
     semicolons where you would in a normal program.
-E commandline
     behaves just like -e, except that it implicitly enables all optional features (in the main
     compilation unit). See feature.
-i[extension]
     specifies that files processed by the "<>" construct are to be edited in-place.  It does this by
     renaming the input file, opening the output file by the original name, and selecting that output
     file as the default for print() statements.  The extension, if supplied, is used to modify the name
     of the old file to make a backup copy, following these rules:

            If no extension is supplied, no backup is made and the current file is overwritten.

            If the extension doesn't contain a "*", then it is appended to the end of the current filename as a
            suffix.  If the extension does contain one or more "*" characters, then each "*" is replaced with
            the current filename.  In Perl terms, you could think of this as:

                ($backup = $extension) =~ s/\*/$file_name/g;

            This allows you to add a prefix to the backup file, instead of (or in addition to) a suffix:

                $ perl -pi'orig_*' -e 's/bar/baz/' fileA    # backup to 'orig_fileA'

            Or even to place backup copies of the original files into another directory (provided the directory
            already exists):

                $ perl -pi'old/*.orig' -e 's/bar/baz/' fileA # backup to 'old/fileA.orig'

            These sets of one-liners are equivalent:

                $ perl -pi -e 's/bar/baz/' fileA            # overwrite current file
                $ perl -pi'*' -e 's/bar/baz/' fileA         # overwrite current file

                $ perl -pi'.orig' -e 's/bar/baz/' fileA     # backup to 'fileA.orig'
                $ perl -pi'*.orig' -e 's/bar/baz/' fileA    # backup to 'fileA.orig'

            From the shell, saying

                $ perl -p -i.orig -e "s/foo/bar/; ... "

            is the same as using the program:

                #!/usr/bin/perl -pi.orig
                s/foo/bar/;

            which is equivalent to

                #!/usr/bin/perl
                $extension = '.orig';
                LINE: while (<>) {
                    if ($ARGV ne $oldargv) {
                        if ($extension !~ /\*/) {
                            $backup = $ARGV . $extension;
                        }
                        else {
                            ($backup = $extension) =~ s/\*/$ARGV/g;
                        }
                        rename($ARGV, $backup);
                        open(ARGVOUT, ">$ARGV");
                        select(ARGVOUT);
                        $oldargv = $ARGV;
                    }
                    s/foo/bar/;
                }
                continue {
                    print;  # this prints to original filename
                }
                select(STDOUT);

            except that the -i form doesn't need to compare $ARGV to $oldargv to know when the filename has
            changed.  It does, however, use ARGVOUT for the selected filehandle.  Note that STDOUT is restored
            as the default output filehandle after the loop.

            As shown above, Perl creates the backup file whether or not any output is actually changed.  So this
            is just a fancy way to copy files:

                $ perl -p -i'/some/file/path/*' -e 1 file1 file2 file3...
            or
                $ perl -p -i'.orig' -e 1 file1 file2 file3...

            You can use "eof" without parentheses to locate the end of each input file, in case you want to
            append to each file, or reset line numbering (see example in "eof" in perlfunc).

            If, for a given file, Perl is unable to create the backup file as specified in the extension then it
            will skip that file and continue on with the next one (if it exists).

            For a discussion of issues surrounding file permissions and -i, see "Why does Perl let me delete
            read-only files?  Why does -i clobber protected files?  Isn't this a bug in Perl?" in perlfaq5.

            You cannot use -i to create directories or to strip extensions from files.

            Perl does not expand "~" in filenames, which is good, since some folks use it for their backup
            files:

                $ perl -pi~ -e 's/foo/bar/' file1 file2 file3...

            Note that because -i renames or deletes the original file before creating a new file of the same
            name, Unix-style soft and hard links will not be preserved.

            Finally, the -i switch does not impede execution when no files are given on the command line.  In
            this case, no backup is made (the original file cannot, of course, be determined) and processing
            proceeds from STDIN to STDOUT as might be expected.
-0[octal/hexadecimal]
     specifies the input record separator ($/) as an octal or hexadecimal number.  If there are no
     digits, the null character is the separator.  Other switches may precede or follow the digits.  For
     example, if you have a version of find which can print filenames terminated by the null character,
     you can say this:

         find . -name '*.orig' -print0 | perl -n0e unlink

     The special value 00 will cause Perl to slurp files in paragraph mode.  Any value 0400 or above will
     cause Perl to slurp files whole, but by convention the value 0777 is the one normally used for this
     purpose.

     You can also specify the separator character using hexadecimal notation: -0xHHH..., where the "H"
     are valid hexadecimal digits.  Unlike the octal form, this one may be used to specify any Unicode
     character, even those beyond 0xFF.  So if you really want a record separator of 0777, specify it as
     -0x1FF.  (This means that you cannot use the -x option with a directory name that consists of
     hexadecimal digits, or else Perl will think you have specified a hex number to -0.)
-m[-]module
-M[-]module
-M[-]'module ...'
-[mM][-]module=arg[,arg]...
     -mmodule executes "use" module "();" before executing your program.

     -Mmodule executes "use" module ";" before executing your program.  You can use quotes to add extra
     code after the module name, e.g., '-MMODULE qw(foo bar)'.

     If the first character after the -M or -m is a dash (-) then the 'use' is replaced with 'no'.

     A little builtin syntactic sugar means you can also say -mMODULE=foo,bar or -MMODULE=foo,bar as a
     shortcut for '-MMODULE qw(foo bar)'.  This avoids the need to use quotes when importing symbols.
     The actual code generated by -MMODULE=foo,bar is "use module split(/,/,q{foo,bar})".  Note that the
     "=" form removes the distinction between -m and -M.

     A consequence of this is that -MMODULE=number never does a version check, unless "MODULE::import()"
     itself is set up to do a version check, which could happen for example if MODULE inherits from
     Exporter.
source manpages: perlrun