sub shuffle { my $array = shift; my $i; for ($i = @$array; --$i; ) { my $j = int rand ($i+1); next if $i == $j; @$array[$i,$j] = @$array[$j,$i]; } } my $counter = 10; # this is the number of images you want open DAT, "ads.dat" or die "Error: cannot open data file!"; my @item; while (my $c=) { my ($id,$image,$url)=split(/\|/,$c); push @item, {"image"=>$image,"url"=>$url,"desc"=>$desc}; } close DAT; while ($counter) { my @itemtmp = @item; shuffle(\@itemtmp); while (my $i = pop @itemtmp) { $img = $i->{"image"}; $link = $i->{"url"}; print qq|Set-Cookie: URL=$link\n|; print qq|Location: $img\n\n|; last if --$counter == 0; } }