use warnings; use strict; my @array = (1..20); my @array3 = sort { $a <=> $b } map { $_ % 5 } @array; print join(', ', @array3);