use strict; use warnings; my @data = ( { vtype_ug => 1, total_rate => 400, }, { total_rate => 220, }, { total_rate => 700, vtype_ug => 1, }, { total_rate => 300, }, { total_rate => 400, }, { total_rate => 250, }, ); my @sorted = sort { -(exists $a->{vtype_ug} <=> exists $b->{vtype_ug}) || $a->{total_rate} <=> $b->{total_rate} } @data; use Data::Dumper; print Dumper @sorted;