The Perl ucfirst function takes a string, converts its first character in uppercase and than returns the new string.
The syntax forms of the ucfirst function are as follows:
ucfirst EXPR
ucfirst
It returns the value of EXPR with its first character in uppercase.
If the argument is a string variable, this function returns the variable with its first character uppercase, but it doesn’t alter the content of the variable.
In the second syntax form, EXPR is omitted, so the Perl ucfirst 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 uppercase, the function will do nothing.
The following simple example shows you how to convert the first character of a string in uppercase, using the ucfirst function:
# initialize a string variable
my $str = "an example about ucfirst function";
my $newStr = ucfirst $str;
print "$newStr\n";
# it prints: An example about ucfirst function