open IN, $infile or die "Can't open input file: $!"; #### my %set; my $substit = ""; for (1..26) { my $randchar; do { $randchar = chr((int rand 26) + 65) } while $set{$randchar}++; $substit .= $randchar; } #### my @alpha = split //, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; #### my @crypt = @alpha; fisher_yates_shuffle(\@crypt); #### my $substit = join '', @crypt; #### sub fisher_yates_shuffle { my $array = shift; for (my $i = @$array; --$i; ) { my $j = int rand ($i+1); next if $i == $j; @$array[$i, $j] = @$array[$j, $i]; } return join '', @$array; } #### Benchmark: timing 5000 iterations of orig, f_yates, hash... orig: 33 secs (23.60 usr 0.00 sys = 23.60 cpu) f_yates: 5 secs ( 2.88 usr 0.00 sys = 2.88 cpu) hash: 13 secs ( 5.68 usr 0.00 sys = 5.68 cpu)