use strict; use warnings; use Data::Dumper; my $data = [ { 'Color' => 'green', 'Step' => 'Platform', 'acc' => '1111', 'Date' => '08-06-2022' }, { 'Color' => 'black', 'Step' => 'Platform', 'acc' => '1111', 'Date' => '01-05-2019' }, { 'Color' => 'blue', 'Step' => 'Platform', 'acc' => '1111', 'Date' => '10-11-2020' }, { 'Color' => 'white', 'Step' => 'Platform', 'acc' => '1111', 'Date' => '01-03-2022' }, { 'Color' => 'red', 'Step' => 'Platform', 'acc' => '1111', 'Date' => '03-21-2021' }, ]; my @sorted = map { $_->[1] } # Drop the date key keeping only the payload sort { $a->[0] cmp $b->[0] } # Sort based on date key map { [to_iso8601($_->{Date}), $_] } # Temporarily store tuples of transformed date key, payload @$data; print Dumper \@sorted; sub to_iso8601 { my $date = shift; # Extract the components of a mm-dd-yyyy format my %components; @components{qw(month day year)} = split /-/, $date; # Enforce month and date must be 2 digits, possibly adding a leading 0. $components{$_} =~ s/^(\d{1})$/0$1/ for qw(day month); # Return them as a string with the components rearranged as yyyy-mm-dd # (ISO8601) return join '-', @components{qw(year month day)}; }