For example, the two web frameworks Mojolicious and Dancer (or Dancer2), or maybe even the raw Plack interface allow you to do that, and they each come with a built-in web server as well.
Your program could look like the following, adapted from the Mojolicious::Lite synopsis:
# Automatically enables "strict", "warnings", "utf8" and Perl 5.16 f
+eatures
use Mojolicious::Lite -signatures;
# Route with placeholder
get '/' => sub ($c) {
my $foo = $c->param('foo');
$c->render(text => "Hello from $foo.");
run_main_program();
};
# Start the Mojolicious command system
app->start;