#!/usr/bin/env perl use strict; use warnings; use Benchmark 'cmpthese'; my $str = 'xyz'; my $re = qr{^xyz$}; cmpthese 0 => { use_m => \&use_m, as_qr => \&as_qr, use_o => \&use_o, raw_m => \&raw_m, raw_o => \&raw_o, }; sub use_m { $str =~ m/$re/ and return; } sub as_qr { $str =~ $re and return; } sub use_o { $str =~ m/$re/o and return; } sub raw_m { $str =~ m/^xyz$/ and return; } sub raw_o { $str =~ m/^xyz$/o and return; }