#!/usr/bin/perl -w use Benchmark; my $txt = 'find this regex'; my $str = 'regex?'; my $rgx = qr/$str/i; timethese ( 1000000, { match => sub{ $txt =~ m/$str/i }, qreg => sub{ $txt =~ $rgx }, }, ); #### % test.pl Benchmark: timing 1000000 iterations of match, qreg... match: 1 wallclock secs ( 0.82 usr + 0.00 sys = 0.82 CPU) @ 1219512.20/s (n=1000000) qreg: 0 wallclock secs ( 0.73 usr + 0.00 sys = 0.73 CPU) @ 1369863.01/s (n=1000000)