#!/usr/bin/perl -w use Benchmark; our $nonspace = ('abc' x 100) . "\n"; our $space = ('a c' x 100) . "\n"; Benchmark::cmpthese(-1, { space => q{ my $copy = $space; $copy =~ s/\s+\z// }, nonspace => q{ my $copy = $nonspace; $copy =~ s/\s+\z// }, }); Rate space nonspace space 32880/s -- -89% nonspace 300755/s 815% --