in reply to while condition bubbleSort

use strict; use warnings; my @list2 = sort { $a <=> $b } @list;
I thought should solve your problem (unless bubble sort is kind of a exercise that you need to do).