Extract all public GPG keys from a file

Suppose you have a file named "file-with-keys-gpg" and want to extract it by deleting any other line in the file.

perl -ne 'print if /-----BEGIN PGP PUBLIC KEY BLOCK-----/../-----END PGP PUBLIC KEY BLOCK-----/' file-with-keys-gpg

Of course by extrapolating the logic we might want to print all the lines between two regexp

perl -ne 'print if /regex1/../regex2/' file.txt