To remove the last character of a string in Perl, you can use substr function with the length of the string minus 1.
In this example,
str1
with a value of "Hello World"
.$str1 = "Hello World";
$str1 = substr($str1, 0, -1);
print "Modified string is: $str1";
Modified string is: Hello Worl
In this example,
str2
with a value of "apple"
.$str2 = "apple";
$str2 = substr($str2, 0, -1);
print "Modified string is: $str2";
Modified string is: appl
In this tutorial, we learned How to Remove Last Character in a String in Perl language with well detailed examples.