To remove a specific substring from a string in Perl, you can use the `s///` substitution operator.
In this example,
$str
with a value of "Hello World"
.s///
operator with the pattern /World/
and replacement ""
to remove the specified substring.s///
operator modifies the string in place.$str
to the console.$str = "Hello World";
$str =~ s/World//;
print "Modified string: $str\n";
Modified string: Hello
In this example,
$text
with a value of "I like apple pie"
.s///
operator with the pattern /apple/
and replacement ""
to remove the specified substring.s///
operator modifies the string in place.$text
to the console.$text = "I like apple pie";
$text =~ s/apple//;
print "Modified string: $text\n";
Modified string: I like pie
In this tutorial, we learned How to Remove specific Substring in Perl language with well detailed examples.