Take a look at sort -V and ls -v source code.
Also this is a program I wrote before those other programs learned about version sorting.
#!/usr/bin/perl
@S = <>;
print sort byglob @S;
######################################################################
#
# Sorting function which sorts numerically for numerical parts,
# alphabetically otherwise
# 
sub byglob
{
  my($A) = $a;
  my($B) = $b;
  my($c,$d,$e);
  while ($A && $B)
    {
      $A =~ s/^([0-9]+|[^0-9]+)//;
      $c = $1;
      $B =~ s/^([0-9]+|[^0-9]+)//;
      $d = $1;
      if ($c =~ /\d/ && $d =~ /\d/)
        {
          $e = $c <=> $d;
        }
      else
        {
          $e = $c cmp $d;
        }
      return $e if ($e);
    }
  return $a cmp $b;
}