Mega Code Archive

 
Categories / Perl / Regular Expression
 

Using Patterns with Substitutions

#The s operator substitutes data that match a pattern with replacement data.  #$variable =~ s/pattern/substitution/; #The s operator returns the number of substitutions made or 0 if none occurred. #!/usr/bin/perl -w $p = "Jack, Software Engineer"; $p =~ s/Software Engineer/Tester/; print "New title: $p.\n";