The intention of the code is to take everything after the last backslash (if there is one) up to the last dot (if there is one after the last backslash)
You could extract that 'proj' fragment from the paths something like this (in your substring routine):
my ($name) = $file =~ /([^\\]+?) # everything but backsla +shes, non-greedy (?:\.[^\\.]*)? $ # optional .ext, anchore +d at the end /x;
i.e., if there is an extension, the non-greediness of the captured first part lets the extension be matched by the optional second part, so it isn't included in the captured substring. Otherwise, you simply capture everything-but-backslashes at the end of the path.
Whether that's more elegant is a matter of personal taste, though.
In reply to Re: Inelegant code to compare file names
by Eliya
in thread Inelegant code to compare file names
by davies
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |