#!/usr/bin/env perl -l use strict; use warnings; use Benchmark 'cmpthese'; my %seq = ( 'W X Y' => 'WbbbXbbbY', 'X Y' => 'XbbbY', 'X Y Z' => 'XbbbYbbbZ', ); print 'Sanity Tests:'; print 'kcott: >', kcott_code(), '<'; print 'marshall: >', marshall_code(), '<'; cmpthese 0 => { K => \&kcott_code, M => \&marshall_code, }; sub kcott_code { my $re = qr{(@{[join '|', sort { length $b <=> length $a } keys %seq]})}; return $re; } sub marshall_code { my $search_phrases = join '|', sort { length $b <=> length $a } keys %seq; my $re = qr{($search_phrases)}; return $re; }