my @sorted = map { $_->{total_rate} *= -1 if $_->{vtype_ug}; $_ } sort { $a->{total_rate} <=> $b->{total_rate} } map { $_->{total_rate} *= -1 if $_->{vtype_ug}; $_ } @array ;