#!/usr/bin/perl use strict; use warnings; use 5.010; use utf8; use Benchmark qw(:all :hireswallclock) ; my $DATA = <<'DATA'; T est 123 A ha a a a a aaaa s a s sssssssssssssssssssssss ssssssssssssssss sssssssssssssssss dd ddddd aaa 111 ddd fff a fg fff fff a DATA my $c1 = <<'CODE'; $DATA =~ s/^[\s\u200c]+|[\s\u200c]+$//g; print $DATA; CODE my $c2 = <<'CODE'; my $re = qr(^[\s\u200c]+|[\s\u200c]+$); $DATA =~ s/$re//g; print $DATA; CODE timethis(10_000_000,$c1); timethis(10_000_000,$c2);