use Benchmark; sub a { $_ = "this is a\ntest\n"; s/(?:\s+|\n+)//gc; } sub b { $_ = "this is a\ntest\n"; s/\s+//gc; } sub c { $_ = "this is a\ntest\n"; tr/\n\r\t //d; } timethese(250000,{ a => \&a, b => \&b, c => \&c }); Benchmark: timing 250000 iterations of a, b, c... a: 5 wallclock secs ( 4.18 usr + 0.01 sys = 4.19 CPU) @ 59665.87/s (n=250000) b: 1 wallclock secs ( 1.61 usr + 0.03 sys = 1.64 CPU) @ 152439.02/s (n=250000) c: 1 wallclock secs ( 0.66 usr + 0.02 sys = 0.68 CPU) @ 367647.06/s (n=250000)