CPAN is a collection of Perl Modules. You can search for modules e.g. via the metacpan page. For each module, you can read through the documentation to see if it can help you. If you want to install it, go to the command line and type cpan Interesting::Module
. After the module is installed and tested, you can use it in your programs.
This usually looks like
use Interesting::Module 'interesting_function';
my $answer = interesting_function(42);
Code reuse is good, because you have to write less complicated code yourself: Others already did it. Some things are difficult to do correctly – using a module means less stuff to think about. But you should always read the documentation of a module in order to apply it correctly.
As an example, people used to write CGI programs with their own URL decoding. But that is unneccessarily repeated code! There are various modules that have helper functions to do exactly that, and can correctly parse query strings. The same holds for databases – properly using a module makes it easier to avoid SQL injection vulnerabilities.
Of course, serious web development has moved beyond CGI. In Perl the following web app frameworks are well-known:
If you just want to try out one of these frameworks, then Dancer is probably more lightweight and easier to use than the others.