You can implement it yourself, you just need to separate the repeated logic into a subroutine and call the subroutine recursively from itself when a directory is encountered.
Another possibility would be to use File::Find to walk the directories for you. $File::Find::name will contains the relative path to each of the files/directories.