What are good alternatives to substitution s///, and how do they compare?

In Perl, the substitution operator s/// is powerful for replacing text within strings. However, there are alternatives that may fit specific use cases better, such as the use of regular expressions or string functions. This guide explores these options and their comparisons.
Perl, substitution, regular expressions, string functions, text replacement

# Using regex to match and modify a string
my $string = "Hello World!";
$string =~ /World/ and $string =~ s/World/Perl/;
print $string;  # Output: Hello Perl!

# Using the tr/// operator for transliteration
my $text = "apple orange banana";
$text =~ tr/orange/lemon/; 
print $text;  # Output: apple lemon banana
    

Perl substitution regular expressions string functions text replacement