my @sorted= grep { s#0.{4}(\d+),(0*)!#$2$1#gs; 1 } sort grep { s#(0*)(\d+)#"0".pack("N",length$2)."$2,$1!"#ge; 1 } @{[ @list ]};