Perl's inbuilt sort function sorts array in ASCII character code. But to sort an array numerically we can use the space ship operator <=>.

 

{code}

@array = sort { $a <=> $b } @oldarray;

{/code}

 

Here is an example:

{code}

@array = (5,3,2,6,8,12,15);

@sorted = sort { $a <=> $b} @array;

print @sorted;

{/code}