in reply to count words in a line


To match arbitrary words use \w+ instead of "perlmonk":
#!/usr/bin/perl -wl use strict; my $line1 = "perlmonk perlmonk perlmonk"; my $count1 = () = $line1 =~ /perlmonk/g; my $line2 = "perl m onk p erlmonk per lm onk"; # Remove the spaces and count as before $line2 =~ s/ //g; my $count2 = () = $line2 =~ /perlmonk/g; print for $count1, $count2; __END__ Prints: 3 3

--
John.