To remove a character at a specific index in a string in Perl, you can use substr.
In this example,
$str1
with a value of "Hello World"
.substr
function to remove the character at the specified index.my $str1 = "Hello World";
my $index_to_remove = 6;
substr($str1, $index_to_remove, 1, "");
print "Modified string is: $str1";
Modified string is: Hello orld
In this example,
$str2
with a value of "apple"
.substr
function to remove the character at the specified index.my $str2 = "apple";
my $index_to_remove = 2;
substr($str2, $index_to_remove, 1, "");
print "Modified string is: $str2";
Modified string is: aple
In this tutorial, we learned How to Remove Character at specific Index in a String in Perl language with well detailed examples.