my @sorted = map { $_->[1] } sort { $b->[0] <=> $a->[0] } map { [ (stat)[9], $_ ] } glob('*'); { # diagnostic local $, = ' '; print @sorted; } my @results = grep { /^$mask/ig } @sorted; print "Your file is: ", $results[$position-1], $/; #### my @candidates = grep { /^$mask/ig } glob('*'); my @sorted = map { $_->[1] } sort { $b->[0] <=> $a->[0] } map { [ (stat)[9], $_ ] } @candidates; print "Your file is: ", $sorted[$position-1], $/ if defined $sorted[$position-1];