#!/usr/local/bin/perl use Benchmark; my $str = "the %0A quick %2b brown %63 fox %63 jumped %24 over %7e the %4f%45 lazy %25 dog"; timethese (500000, { 'myway' => sub { $_ = $str; while (/%[0-9A-Fa-f]{2}/) { $_ = $&; /[0-9A-Fa-f]{2}/; $ob[0] = hex($&); $temp = pack("C*", @ob); $name =~ s/%[0-9A-Fa-f]{2}/$temp/; $_ = $name; } }, 'regexpway' => sub { $_ = $str; s/%([a-fA-F0-9]{2})/pack("C", hex($1))/eg; }, }); Benchmark: timing 500000 iterations of myway, regexpway... myway: 23 wallclock secs (21.99 usr + 0.00 sys = 21.99 CPU) regexpway: 57 wallclock secs (57.58 usr + 0.00 sys = 57.58 CPU)