To reverse a string in Perl, you can use the reverse
function.
In this example,
$str1
with a value of "Hello World"
.reverse
function on $str1
.$str1 = "Hello World";
$reversed_str1 = reverse $str1;
print "Reversed string is: $reversed_str1\n";
Reversed string is: dlroW olleH
In this example,
$str2
with a value of "apple"
.reverse
function on $str2
.$str2 = "apple";
$reversed_str2 = reverse $str2;
print "Reversed string is: $reversed_str2\n";
Reversed string is: elppa
In this tutorial, we learned How to Reverse a String in Perl language with well detailed examples.