Where did you get the scripts? There should be some instruction about where to place them.
In order to run CGI, the module cgi must be activated.
The default location for CGI scripts in Apache2 is /usr/lib/cgi-bin/ but that is almost always changed when actually writing CGI scripts. Your vhost should point to the location and make the appropriate settings. e.g.
sudo a2enmod cgi
sudo service apache2 restart
That will make a script, such as /usr/lib/cgi-bin/x.pl, available via the local host, such as http://127.0.0.1/cgi-bin/x.pl Note the ScriptAlias and Directory directives and how they work.
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Require all granted
For the script to run, it has to be executable (mode 555, 755, or 775) and of course can't contain errors.
You might want to put http://localhost/cgi-bin/ behind a password or block outside access with the firewall while getting things set up.