Clear the 'will NOT be used by the installed perl interpreter' warning
The hook and messages are confirmed on this machine: /usr/share/libalpm/hooks/detect-old-perl-modules.hook is owned by perl 5.42.2-2, and /usr/share/libalpm/scripts/detect-old-perl-modules.sh prints both quoted WARNING lines and the unowned-files find command used in the fix. yay --help lists --rebuild. The defect is the held-back case, which is the case the record's only source (thread 270501) actually documents. The script warns about every /usr/lib/perl5 directory that is not the running perl's version. When perl is held back, that is the NEWER directory: in the thread perl stayed at 5.32 and the warning named 5.34 with 42 repository packages. The record's cause describes only an old directory, and its fix tells the reader to look for perl in pacman -Qqo output, which perl never appears in for that case, using a hard-coded 5.40 that will not match most readers. The thread also shows the next obstacle, an AUR package requiring perl<5.33 that blocks the perl upgrade. The full update command was missing for Omarchy, where pacman -Syu is refused by the ALPM guard. Nothing was rebuilt or removed.
Symptom
After an upgrade that touched perl, the transaction ends with:
(5/9) Checking for old perl modules...
WARNING: '/usr/lib/perl5/5.40' contains data from at least 3 packages which will NOT be used by the installed perl interpreter.
-> Run the following command to get a list of affected packages: pacman -Qqo '/usr/lib/perl5/5.40'
Sometimes also WARNING: 12 file(s) in /usr/lib/perl5/5.40 are not tracked by pacman and need to be rebuilt. Perl scripts or tools that use those modules start failing with Can't locate Foo/Bar.pm in @INC.
Cause
Arch installs perl modules into a directory named for the perl major version, such as /usr/lib/perl5/5.42/, and the interpreter only reads its own version's directory. The detect-old-perl-modules.hook, shipped by the perl package, warns about every other version directory under /usr/lib/perl5 that still holds files. That happens two ways. Usually the directory is OLDER than the running perl: repository packages were rebuilt by Arch, and what remains is AUR or other foreign perl packages built against the old perl, or files installed by cpan. Sometimes the directory is NEWER than the running perl: perl itself is held back (IgnorePkg, --ignore perl, or a package that requires an older perl) while every module package moved on, so the warning names the new directory and lists ordinary repository packages.
Fix
Compare the directory the WARNING names with the running perl:
perl -e 'print "$^V\n"'
ls /usr/lib/perl5/
Set dir to the directory the WARNING names. The example below uses 5.40:
dir=/usr/lib/perl5/5.40
pacman -Qqo "$dir"
**The named directory is NEWER than the running perl.** perl is held back. Check for it in IgnorePkg:
pacman-conf IgnorePkg
Remove perl from IgnorePkg with sudoedit /etc/pacman.conf, then do a full upgrade:
# Omarchy 4
omarchy update
# Plain Arch
sudo pacman -Syu
If the upgrade stops with installing perl (...) breaks dependency 'perl<5.xx' required by <package>, that package (usually from the AUR) pins the old perl. Rebuild it against the new perl or remove it, then run the upgrade again.
**The named directory is OLDER than the running perl.** Rebuild each listed foreign package against the new perl:
pacman -Qqm | grep -xFf <(pacman -Qqo "$dir")
yay -S --rebuild <package> <package>
A repository package in pacman -Qqo "$dir" that is not in that foreign list means the system is not fully updated: run the full upgrade above. Remove any listed package you no longer use with sudo pacman -Rns <package>.
For files no package owns (installed with cpan), list them and reinstall those modules with cpan, or delete them:
LC_ALL=C find "$dir" -type f -exec pacman -Qqo {} + |& sed -n 's/^error: No package owns \(.*\)$/\1/p'
Verify
pacman -Qqo "$dir" lists no packages for the directory the warning named, perl -e 'print "$^V\n"' matches the newest directory in ls /usr/lib/perl5/, and the hook prints no WARNING on the next transaction.