11.32. Substitute

  • s/PATTERN/REPLACEMENT/

$line = "abc123def";

$line =~ s/\d+/ /;                          # "abc def"
$line =~ s/([a-z]*)(\d*)([a-z]*)/$3$2$1/;   # "def123abc"

$line =~ s/.../x/;           # "x123def";

$line =~ s/.../x/g;          # "xxx";


$line =~ s/(.)(.)/$2$1/;     # "bac123def"

$line =~ s/(.)(.)/$2$1/g;    # "ba1c32edf"

If you are interested in on-site trainings by the author, please contact me directly.

Online courses:

Would you like to get
updated when I publish
the next article?

Follow me:

Google Plus Twitter RSS feed