/g
. En cualquier otro caso retorna el valor falso.
1 #!/usr/bin/perl -w 2 undef($/); 3 $paragraph = <STDIN>; 4 $count = 0; 5 $count = ($paragraph =~ s/Mister\b/Mr./ig); 6 print "$paragraph"; 7 print "\n$count\n";El resultado de la ejecución es el siguiente:
> numsust.pl Dear Mister Bean, Is a pleasure for me and Mister Pluto to invite you to the Opening Session Official dinner that will be chaired by Mister Goofy. Yours sincerely Mister Mickey Mouse Dear Mr. Bean, Is a pleasure for me and Mr. Pluto to invite you to the Opening Session Official dinner that will be chaired by Mr. Goofy. Yours sincerely Mr. Mickey Mouse 4