#!/usr/bin/perl use warnings; use strict; use Benchmark; sub simple_hash { seek DATA, 0, 0; while () {last if /^Names/} my %lookup; while () { next if /^\s*$/; last if /^Example List/; chomp; my ($first, $second)=split; $lookup{$first}=$second; } while () { next if /^\s*$/; chomp; my ($name, $rest)=split /\s+/, $_, 2; print $lookup{$name}, "\t", $rest, "\n"; } } sub funky_regex { seek DATA, 0, 0; while () {last if /^Names/} my $regex_string=""; while () { next if /^\s*$/; last if /^Example List/; chomp; my ($first, $second)=split; $regex_string.="s/$first/$second/;"; } local $/; $_=(); eval $regex_string; print ; } timethese(5000000, { 'simple_hash' => &simple_hash, 'funky_regex' => &funky_regex } ); __DATA__ Names Guido Meyer Mike Smith Klaus Rothschild Mick Mouse Daffy LeCannard Example List Guido bla1 ... Mike bla2 ... Klaus bla3 ... Mick blahsome more Daffy lookout Duck ! # results funky_regex: 0 wallclock secs ( 0.30 usr + 0.00 sys = 0.30 CPU) @ 16666666.67/s (n=5000000) (warning: too few iterations for a reliable count) simple_hash: 0 wallclock secs ( 0.01 usr + 0.00 sys = 0.01 CPU) @ 500000000.00/s (n=5000000) (warning: too few iterations for a reliable count)