#!/usr/bin/perl
print ("Enter a string: ");
my $i;
my $string = <STDIN>;
@string=split//,$string;
print ("The reverse of this string is:\n");
for ($i = $#string; $i >= 0; $i--)
{
print $string[$i];
}
print ("\n\n");
Execution
Enter a string: The Internet is a network of networks.
The reverse of this string is:
.skrowten fo krowten a si tenretnI ehT
Enter a string: RATS LIVE ON NO EVIL STAR
The reverse of this string is:
RATS LIVE ON NO EVIL STAR
Enter a string: University of California, Berkeley is one of the top Engineering institutions in the United States.
The reverse of this string is:
.setatS detinU eht ni snoitutitsni gnireenignE pot eht fo eno si yelekreB ,ainrofilaC fo ytisrevinU