in reply to how to run a specific file from a list of filenames in a folder

G'day alenaustin,

Welcome to the Monastery.

I don't see the need for the foreach loop:

$ > Y $ > X $ > Z $ perl -E 'my @f = qw{X Y Z}; say "@f"; @f = sort { -M $b <=> -M $a } +@f; say "@f"' X Y Z Y X Z

Perhaps there are aspects of your issue that you haven't told us about. The guidelines in "How do I post a question effectively?" should help you to identify what else you need to tell us.

— Ken