Perl uppercase and lowercase string conversion

Perl lowercase/uppercase string FAQ: How do I convert a string to uppercase or lowercase in Perl?

Solution: To convert a string to all uppercase characters use the Perl uc function, and to convert them to lowercase use the lc function.

Here are a couple of examples to help demonstrate this Perl uppercase/lowercase string conversion.

Perl uppercase string conversion

Here's a Perl uppercase example, converting a Perl string from whatever it was to all uppercase characters:

# create a perl string
$a = 'foo bar';

# convert the string to uppercase
$b = uc $a;

# print it
print $b;

In this example our code prints the string "FOO BAR".

Perl lowercase string conversion

Here's a Perl lowercase example, converting a Perl string from whatever it was to all lowercase characters:

# create a perl string
$a = 'FOO BAR';

# convert the string to lowercase
$b = lc $a;

# print it
print $b;

In this example our Perl script prints the string "foo bar".

Perl uppercase and lowercase examples

Of course there are ways to make both of these Perl uppercase and lowercase examples shorter, but I'm trying to be clear in these examples.