#!/usr/local/bin/perl -w use strict; use Benchmark; my $count = 900000; ## Method number two sub One { my $data='for-bar-baz'; $data =~tr/-/_/; } ## Method number Two sub Two { my $data='for-bar-baz'; $data =~s/-/_/g; } ## We'll test each one, with simple labels timethese ( $count, {'Method One TR' => '&One', 'Method Two s'=> '&Two' } ); exit; #### Benchmark: timing 500000 iterations of Method One TR, Method Two s... Method One TR: 2 wallclock secs ( 1.87 usr + 0.00 sys = 1.87 CPU) @ 267379.68/s (n=500000) Method Two s: 5 wallclock secs ( 4.84 usr + 0.00 sys = 4.84 CPU) @ 103305.79/s (n=500000)