#! /usr/bin/perl use strict; use warnings; use List::Util qw{ shuffle }; my @numbers = shuffle(1 .. 50); for my $index (0 .. $#numbers) { # replace with 0 .. 25 to stop after 5 lines. print $numbers[$index], $index % 5 == 4 ? "\n" : ' '; }