use Sort::Key::Multi qw(ii_keysort); # ii => two integer keys my @sorted = ii_keysort { /(\d+)_(\d+)$/ } @data;