collection of one-liners, a part is adapted from such a list by Tom Christianson, one of the authors of "Programming Perl". # the always present hallo world program, adapted to a Math department perl -e 'print "Hello Mr Euler!\n"' # rename in each file name the string aaa by bbb ls | perl -ne 'chomp; next unless -e; $o = $_; s/aaa/bbb/; next if -e; rename $o, $_'; # add first and last column in each line of file foo.txt and print it out perl -lane 'print $F[0] + $F[-1]' foo.txt # print lines 15 to 17 of file foo.txt perl -ne 'print if 15 .. 17' foo.txt # a second way to print lines 3 to 5 of file foo.txt perl -pe 'exit if 3<$. && $.<5' foo.txt # change all words "foo"s to "bar"s in every .c file and keep backups perl -p -i.bak -e 's/\bfoo\b/bar/g' *.c # the same but without backup. Remember the flags: "eat the pie" perl -p -i -e 's/foo/bar/g' *.c # changes ^M newline characters to newlines perl -p -i -e 's/\012?\015/\n/g' $1 # the same but with all files with name filename perl -p -i -e 's/foo/bar' `find . -name "filename"` # substitution can also be applied to binary files like test.ppm perl -p -i -e 's/255/127/g' test.ppm # substitute "xyz.math" to "abc.math" in every .html file and keep backups perl -p -i.bak -e 's/xyz\.math/abc\.math/g' *.html # insert department name after each title and keep backup perl -p -i.bak -e 's#