# File: subst1.pl # Title: Substitution in String. Examples # Author: Mihaela Malita $str = "Mihaela Malita\n\nMelanie Marcu" ; print "String is $str"; $str =~ s/^\s*$//g ; print "\nRemove blank lines: ", $str; $str =~ s/ //g ; print "\nDelete all blanks: ",$str; $str =~ s/\s//g ; # second s stands for [\t\n\r\f] print "\nRemove white spaces,tab, newline, return,formfeed:",$str; $str =~ s/m//gi ; print "\nDelete all occurrences of m-ignore case(i): ",$str; $str =~ s/a/a /g ; print "\nPut blanks after each a: ",$str; $str =~ s/....// ; print "\nDelete first 4 letters: ",$str; $str =~ s/h|i/X/ ; print "\nSubstitute the first h OR i with X: ",$str; #$str =~ s/^([^] +) + ([^ ]+) /$3 $1/; #print "\nSwap first two words: ",$str; $str =~ s/\W.*//; print "\nGet rid of everything after first word: ",$str; exit;