my @list = map {substr($_, 1)} sort map {$lookup{$_}{val} > 0 ? "A$_" : "B$_"} @list;