Perl lcfirst Function

The lcfirst function is used to convert the first character of a string in lowercase and to return the new string.

The Perl lcfirst takes a string, converts its first character in lowercase and than returns the new string.

There are two syntax forms for this function:

lcfirst EXPR
lcfirst
It returns the value of EXPR with its first character in lowercase. If the argument is a string variable, this function returns the variable with its first character lowercased, but it doesn’t alter the content of the variable.

In the second syntax form, EXPR is omitted, so the Perl lcfirst function uses the special variable $_. As with other functions, you can use or omit the parentheses, as you like. If the first letter of the string expression is lowercase, the function will do nothing.

The following simple example shows you how to convert the first character of a string in lowercase, using the Perl lcfirst function:

#!/usr/local/bin/perl
 
use strict;
use warnings;
 
# initialize a string variable
my $str =  "An example about lcfirst function";
my $newStr = lcfirst $str;
print "$newStr\n";
# it prints: an example about lcfirst function