#!/usr/bin/perl use strict; use warnings; # get list of countries: open my $f, '<:encoding(UTF-8)', 'countries' or die "Can't read file: $!"; my @countries = <$f>; close $f; chomp @countries; for (@countries) { s/^([^;]+).*/\u\L$1/; } use Benchmark qw(cmpthese); use List::Util qw(first); my $re = join '|', map quotemeta, @countries; sub regex { die "regex" unless 'Germany' =~ m/^(?:$re)$/; die "regex" if ' Foo' =~ m/^(?:$re)$/; } sub mgrep { die "grep" unless grep { $_ eq 'Germany' } @countries; die "grep" if grep { $_ eq 'Foo' } @countries; } sub mfirst { die "grep" unless first { $_ eq 'Germany' } @countries; die "grep" if first { $_ eq 'Foo' } @countries; } my %hash = map { $_ => 1 } @countries; sub hash { die "hash" unless $hash{Germany}; die "hash" if $hash{Foo}; } cmpthese(-1, { regex => \®ex, grep => \&mgrep, first => \&mfirst, hash => \&hash, });