# mine.pl sub show { my @data = @_; for (@data) { s/\266/%B6/g; s/\267/%B7/g; tr/ /\267/; s/\t/ -> /g; s/\n/\266\n/g; } return wantarray ? @data : join'',@data; } @data = ()[0..7]; my $start = time; for (0..100000) { my @new = show(@data) } printf "Mine takes %d seconds", (time - $start); __DATA__ tab 4 spaces, trailing tab tab and 4 spaces -> tab¶ ····4·spaces,·trailing·tab -> ¶ -> ····tab·and·4·spaces¶ -> -> ¶ ¶ # yours.pl my %mapping = ( "\t" => ' -> ', " " => chr(0267), "\n" => chr(0266)."\n", "\266" => '%B6', "\267" => '%B7', ); my $pattern = qr/([@{[join '', keys %mapping]}])/; sub show { my @data = @_; s/$pattern/$mapping{$1}/g for (@data); return wantarray ? @data : join'',@data; } @data = ()[0..7]; my $start = time; for (0..100000) { my $new = show(@data) } printf "Yours takes %d seconds", (time - $start); __DATA__ tab 4 spaces, trailing tab tab and 4 spaces -> tab¶ ····4·spaces,·trailing·tab -> ¶ -> ····tab·and·4·spaces¶ -> -> ¶ ¶