Memoized prefix and suffix extraction