#!/usr/bin/perl $name = "tom"; # reading through a piped-in file while (<>) { if (/$name/) { print $_; } } # ----- if ("larry, moe, and curly" =~ /\W+(moe)\W+/) { print "$`\n"; print "$&\n"; # NB: not the same as $1 print "$'\n"; } # ----- $_ = "larry, moe, and curly"; s/curly/shemp/; print "$_\n"; # prints "larry, moe, and shemp" $_ = "larry, moe, and curly"; s/(\w+)\W+(\w+)/$2 $1/; # swaps words print "$_\n"; $_ = "larry, moe, and curly had curly hair"; s/curly/shemp/g; print "$_\n"; $_ = "Larry, Moe, and Curly"; s/(\w+)/\U$1/; # makes first word uppercase print "$_\n"; s/(\w+)/\L$1/g; # makes all words lowercase print "$_\n"; # -----