use strict; use warnings; use Benchmark qw(cmpthese); my $pre = 250; my $post = 250; my $baz_match = ('b' x $pre) . 'baz' . ('b' x $post); my $bar_match = ('b' x $pre) . 'bar' . ('b' x $post); my $no_match = ('b' x $pre) . 'bza' . ('b' x $post); print "using_or_index ", using_or_index (), "\n"; print "using_or_noindex ", using_or_noindex (), "\n"; print "using_or_match ", using_or_match (), "\n"; print "using_or_nomatch ", using_or_nomatch (), "\n"; print "using_alt_match ", using_alt_match (), "\n"; print "using_alt_nomatch ", using_alt_nomatch (), "\n"; print "using_set_match ", using_set_match (), "\n"; print "using_set_nomatch ", using_set_nomatch (), "\n"; cmpthese( -1, { using_or_index => \&using_or_index, using_or_noindex => \&using_or_noindex, using_or_match => \&using_or_match, using_or_nomatch => \&using_or_nomatch, using_alt_match => \&using_alt_match, using_alt_nomatch => \&using_alt_nomatch, using_set_match => \&using_set_match, using_set_nomatch => \&using_set_nomatch, }); sub using_or_index { (-1 != index $baz_match, 'bar') or (-1 != index $baz_match, 'baz') ? 1 : 0 } sub using_or_noindex { (-1 != index $no_match, 'bar') or (-1 != index $no_match, 'baz') ? 1 : 0 } sub using_or_match { ($baz_match =~ /bar/ or $baz_match =~ /baz/) ? 1 : 0 } sub using_or_nomatch { ($no_match =~ /bar/ or $no_match =~ /baz/) ? 1 : 0 } sub using_alt_match { ($baz_match =~ /bar|baz/) ? 1 : 0 } sub using_alt_nomatch { ($no_match =~ /bar|baz/) ? 1 : 0 } sub using_set_match { ($baz_match =~ /ba[rz]/) ? 1 : 0 } sub using_set_nomatch { ($no_match =~ /ba[rz]/) ? 1 : 0 }