use Modern::Perl '2014'; my @choices = ( 1 .. 49 ); printf "Lucky numbers: %02d %02d %02d %02d %02d %02d \n\n", sort { $a <=> $b } map { splice @choices, rand(@choices), 1 } ( 1 .. 6 );