$x =~ m!\d+\s*\w+!; # Note that the "m" prefix is required except when the delimiter is "/" $x =~ s!\d+\s*\w+!_!; #### $x =~ m[\d+\s*\w+]; $x =~ s[\d+\s*\w+][_];