shift @chunks if $chunks[0] eq ''; # and then my $s = $chunks[0] =~ /\s/ ? 1 : 0; my $e = $chunks[-1] =~ /\s/ ? -2 : -1;