use strict; use warnings; my @arr=( qw/ F1.jpg F10.jpg F11.jpg F12.jpg F1a.jpg F1b.jpg F2.jpg F3.jpg F4.jpg F5.jpg F6.jpg /); print "$_\n" for sort { my( $aye ) = $a =~ m/(\d+)/; my( $bee ) = $b =~ m/(\d+)/; $aye <=> $bee || $a cmp $b } @arr;