Not always possible. For, consider C as invertible, then by associative properly, B(AC)=(BA)C. Since (AB)C=B(AC)=(BA)C, we get (AB)C=(BA)C implies AB=BA. It implies that A and B are commutative, but in general matrix multiplication is not commutative.