Order and group variables by prefix