Perl array sorting in alphabetical order

Perl has in-built function called sort that can sort contents in array . By default sort function works based on ASCII value. To do sorting based on alphabetical order, we have to use function cmp which is used for comparison and function lc which is used for converting text to lower case.

my @words = qw(foo bar zorg moo);
my @sorted_words = sort { lc($a) cmp lc($b) } @words;
say Dumper \@sorted_words;

Output :-

$VAR1 = [
    'bar',
    'foo',
    'moo',
    'Zorg'
];