The first edition of Programming Perl had a script that did this called travesty. You can download it from https://resources.oreilly.com/examples/9780937175644
When I was learning Perl in the '90s, I remember having a lot of fun running this on different manual pages.