Tutorial: String Manipulation in Perl with s///, y///, and s///g
Perl provides powerful operators for manipulating strings using regular expressions. Here’s a breakdown of each operator with examples: s/// (Substitution Operator) Syntax: s/old-pattern/new-pattern/ Purpose: Replaces occurrences of old-pattern with new-pattern in a string. Example: s/John/Doe/ replaces the first instance of “John” with “Doe”. Example 1: Replace “John” with “Doe” text = "Hello John. John is a friend."; regex = s/John/Doe/; # Result: "Hello Doe. John is a friend." Example 2: Replace “white” with “black” ...