There are many ways to get the last character from a string :
use strict;
my $string = "Hello World";
my $char;
# Use a capturing parenthesis
$char = $1
if ($string =~ /(.)\Z/);
print ">>$string<<\n";
print "[[$char]]";
# Chop the last char away from $string
# this modifies $string
$char = chop $string;
print ">>$string<<\n";
print "[[$char]]";
# use substr :
$char = substr($string,-1);
print ">>$string<<\n";
print "[[$char]]";
perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The
$d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider
($c = $d->accept())->get_request(); $c->send_response( new #in the
HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
Just for the sake of completeness, I wanted to make sure you didn't also forget about 'chomp' - here's the 1st few lines of 'perldoc -f chomp':
chomp VARIABLE
chomp( LIST )
chomp This safer version of "chop" removes any trailing strin
+g that
corresponds to the current value of $/ (also known as
$INPUT_RECORD_SEPARATOR in the "English" module). It r
+eturns
the total number of characters removed from all its arg
+uments.
It’s often used to remove the newline from the end of a
+n input
record when you’re worried that the final record may be
+ missing
its newline. When in paragraph mode ("$/ = """), it re
+moves
all trailing newlines from the string. When in slurp m
+ode ("$/
= undef") or fixed-length record mode ($/ is a referenc
+e to an
integer or the like, see perlvar) chomp() won’t remove
+any-
thing. If VARIABLE is omitted, it chomps $_. Example:
while (<>) {
chomp; # avoid \n on last field
@array = split(/:/);
# ...
}