If you would like to verify that the key and the certificate match you need to compare the modulus in both of the key file and the certificate file. You can check for differences in the modulus rather easily by sending the output of the comparison command to ‘uniq’. If anything shows up, the numbers don’t match and that means that the key and certificate do not match.
$ (openssl x509 -noout -modulus -in server.pem | openssl md5 ;\
openssl rsa -noout -modulus -in server.key | openssl md5) | uniq