#substitution, s/// #s/searchpattern/replacementpattern # + causes the preceding character to match at least once $content = "hotdog"; print "$content\n"; if ($content =~ s/do+g/mydog/) { print "new content : $content\n"; } #\s : a while space character #/g : stands for "global", which tells Perl to replace all matches, and not just the first one. $content = "a lot of white spaces"; print "$content\n"; if ($content =~ s/\s+//g) { print "new content : $content\n"; } $content = "dog1, dog2, dog3"; print "$content\n"; if ($content =~ s/dog/cat/) #without g only replaces first one { print "new content : $content\n"; } $content = "dog1, dog2, dog3"; print "$content\n"; if ($content =~ s/dog/cat/g) { print "new content : $content\n"; } print "\n\n"; $content = "line 1 multiple I am in the middle lines line 3"; #useful for html document decoding if($content =~ m/mu.* .*nes/s) { #/s means to treat string as single line. print "It is found as multiple lines ... \n"; print $&."\n"; }