use strict; use warnings; use Benchmark; my $line = 'x' x 100; open my $frontend, '>>', '/dev/null' or die $!; Benchmark::cmpthese(-1, { _regex => \&_regex, # _unpack1 => \&_unpack1, _unpack2 => \&_unpack2 }); sub _regex { my $tmp_line = $line; if( length $tmp_line < 4000 ){ $tmp_line .= "\t" x 30; } else{ $tmp_line =~ s/(.{4000})/$1\t/g; } print $frontend $tmp_line; } sub _unpack2 { my $tmp_line = $line; my $len = length($tmp_line); my $pos = 0; my $tab = 30; if( length $tmp_line < 4000 ){ $tmp_line .= "\t" x 30; } else { while ( my $s = unpack("x$pos A4000", $tmp_line) ) { $tab--; print $frontend "$s\t"; $pos += 4000; last if $pos >= $len; } } print $frontend "\t" x $tab; print $frontend "\n"; }