Help for this page

Select Code to Download


  1. or download this
    $len = length($field);
    $field1 = substr($field, 0, int($len/2));
    $field2 = substr($field, -int($len/2));
    $field = $field1 if ($field1 eq $field2);
    
  2. or download this
    $field =~ s/^(.+)\s*\1/$1/;
    
  3. or download this
    $field =~ s/(.{2,})\s*\1/$1/g;
    
  4. or download this
    $field =~ s/\b(.+)\b\s*\1\b/$1/g;
    
  5. or download this
    sub test1 {
       my $len = length($_[0]);
    ...
    John Johnson
    foo John Johnson bar
    John Smith!John Smith