#!/usr/local/bin/perl -w use Benchmark; $count = 1_000_000; my $thing = "thing"; print "Match eq => ", check_eq(), "\n"; print "Match rx => ", check_rx(), "\n"; print "Match idx => ", check_idx(), "\n"; timethese( $count, { 'eq' => sub{ check_eq() }, 'rx' => sub{ check_rx() }, 'idx' => sub{ check_idx() } } ); $thing = "asdjgfakjgfashdf___thing___asklfhklajsdhlajsdf"; print "Match eq => ", check_eq(), "\n"; print "Match rx => ", check_rx(), "\n"; print "Match idx => ", check_idx(), "\n"; timethese( $count, { 'eq' => sub{ check_eq() }, 'rx' => sub{ check_rx() }, 'idx' => sub{ check_idx() } } ); sub check_eq { ($thing eq "thing")?1:0; } sub check_rx { ($thing =~ /thing/)?1:0; } $i = 0; sub check_idx { ((index $thing,'thing') != -1)?1:0; }