in reply to Re^3: Sorting filenames with custom function
in thread Sorting filenames with custom function

... the numbers presented are zero-padded integers [with three digits each], so the comparison is equivalent.

Aye, there's the rub. The OPer only presents three examples and, in general, about 35% of the info needed to build some robust code. Numeric and string comparison are the same until someone sez "Oh, by the way..."

It's just a guess, but I'd be inclined to fortify myself on the numeric side based on the presence of the word "number" in the OP: confronted with real-world data (whatever that may be), a numeric comparison seems more likely to continue to work.

I was thinking of something along the lines of Marshall:

>perl -wMstrict -le "my @names = qw(FLY_ABC123_01.jpg PG_ABC123_03 SPL_ABC123_02.jpg FOO_ABC123_011 SPL_ABC123_021 SPL_ABC123_021.jpg); sub sort_123 { return map $_->[0], sort { $a->[1] <=> $b->[1] } map [ $_, m{ .* _ (\d+) }xms ], @_ ; } my @sorted = sort_123(@names); print qq{'$_'} for @sorted; " 'FLY_ABC123_01.jpg' 'SPL_ABC123_02.jpg' 'PG_ABC123_03' 'FOO_ABC123_011' 'SPL_ABC123_021' 'SPL_ABC123_021.jpg'