use strict; my ($handle, $c, $rand, %hash, @lines); open($handle, "random.txt"); for (<$handle>) {} # Number of lines in file while ($c < 10) { # now put into $. $rand = int rand($.); if (!$hash{$rand}) { # Get 10 unique, $hash{$rand} = 1; $c++; } # random line numbers } seek($handle, 0, 0); $. = 0; # Reset file while (<$handle>) { # Retrieve chosen if ($hash{$.-1}) { # lines chomp; push(@lines, $_); } } for ($c = @lines; --$c;) { # Shuffle lines my $rand = int rand ($c+1); @lines[$c,$rand] = @lines[$rand,$c]; } print "$_\n" for (@lines); # Display lines close($handle);