#!/usr/bin/perl use strict; use warnings; my @list = qw(a1_2 a1_1 a10_10 a2_10 a2_1 a2_2 a10_1 a10_2 a1_10); my $re = qr/\w(\d+)_(\d+)/; my @sorted = sort { my @A = $a =~ $re; my @B = $b =~ $re; $A[0] <=> $B[0] or $A[1] <=> $B[1]; } @list;