in reply to return $paths only if ...
if (@paths) is simpler.
Improve your skills with Modern Perl: the free book.