If you have an existing script, then I recommend converting it minimally to a modulino if you have not already done so. This will allow you to use it as a library in your (recommended) PSGI web facing application, while retaining your commandline usage.
What is a
modulino? It's simply a script that has a few extra lines in it + some judicious encapsulation of functionality into sub routines so that it can continue to function as the commandline utility you know, but provides a library interface as module. Just the first google hit, but this does a good job of outlining what it looks like
https://perlmaven.com/modulino-both-script-and-module. Like I said, this can be done with minimal refactoring and can allow you to iteratively move towards creating bonefide Perl modules.