Ternary content-addressable memory has been widely used to perform fast routing lookups. It is able to accomplish the best matching prefix searching in O(1) time without considering the number of prefixes and their lengths. As compared to the software-based solutions, the ternary content-addressable memory can offer sustained throughput and simple system architecture. However, it also comes with several shortcomings, such as the limited number of entries, enormous cost and power consumption. Accordingly, an efficient algorithm is proposed to reduce the required size of ternary content-addressable memory. The proposed scheme can eliminate 98% of ternary content-addressable memory entries by adding comparatively little DRAM and, thus, is attractive for IPv6 routing lookup.