Search and replace on command line Is there a tighter (less characters) way to use perl on the command line to search and replace text from STDIN than I've got here? The code below works.

echo hi | perl -e '$a = &lt;STDIN&gt;; $a =~ s/i/o/g; print $a;'
You can use -p option (see perl --help):


  assume loop like -n but print line also, like sed


So the script becomes:

echo hi | perl -pe 's/i/o/g'


which is really compiled to:

$ perl -MO=Deparse -pe 's/i/o/g'
LINE: while (defined($_ = &lt;ARGV&gt;)) {
    s/i/o/g;
}
continue {
    die "-p destination: $!\n" unless print $_;
}
-e syntax OK