There is no universal rule as to how to form perfective verbs from impefective ones or vice versa. You need to memorize for each word whether it's perfective or imperfective. Usually the one with the prefix is the perfective, but with the pair "купить"/"покупать" it's other way round.
They don't even necessarily come in pairs. You can form several perfective verbs using different prefixes to various effects (the prefixes work similar to English prepositions, changing the meaning of the verb), and then turn those into imperfective using a suffix.