As
tangent has already explained in his post,
Sort::Key::Natural breaks the string at the boundaries between alphabetic and number groups. So for instance,
P007b_Yum is equivalent to
P_7_b_Yum.
If you want alphanumeric groups to remain unbroken, you will have to change the sorting-key generation algorithm.
This probably does what you want (untested):
use Sort::Key qw(keysort);
sub mknkey {
my $n = shift;
$n =~ s/^0+//;
my $len = length $n;
my $nines = int ($len / 9);
my $rest = $len - 9 * $nines;
('9' x $nines) . $rest . $n;
}
sub mknatkey {
my $nat = @_ ? shift : $_;
$nat =~ s/(\d+)/mknkey($1)/ge;
$nat;
}
my @sorted = keysort { mknatkey($_) } @data;