We build the regex from the word using \s* in between the letters.
my $word = "perlmonk"; my $re = join('\s*',$word =~ /\w/g); my $qre = qr/$re/; while (<DATA>) { my $count = () = /$qre/g; print "$count == $_"; } __DATA__ perlmonk perlmonk perlmonk perl m onk p erlmonk per lm onk per lm onk
Updated: actually answered question this time.
--
Steve Marvell
In reply to Re: count words in a line
by marvell
in thread count words in a line
by benlaw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |