use strict; use warnings; my $start_time = time; my $n_strings = 10_000; my $min_len_strings = 20; my $max_len_strings = 100; # Generate strings my @number2letter = ('a' .. 'b'); my @strings = (); undef $strings[$n_strings]; foreach my $string (@strings){ $string = ''; for (1 .. $min_len_strings + rand($max_len_strings - $min_len_strings)) { $string .= $number2letter[int rand @number2letter]; } } # Build comparison matrix my @matches = (); undef $matches[$n_strings]; foreach my $match(@matches) { $match = []; undef $match->[$n_strings]; } # And compare for my $i (0 .. $#strings) { for my $j (0 .. $#strings) { $matches[$i][$j] = $strings[$i] eq $strings[$j] ? 1 : 0; } } # And finish my $tot_matches = 0; for my $i (0 .. $#strings) { for my $j (0 .. $#strings) { $tot_matches++ if $matches[$i][$j]; } } my $time = time - $start_time; print "I ran for $time seconds, and found $tot_matches matches.";