Try this:
use strict; use warnings; while ( my $line = <DATA> ) { next unless $line =~ /\band\b/; chomp $line; my @words = split /\s+/, $line; my $location = 0; my @locations; foreach ( @words ) { $location++; push @locations, $location if m/\band\b/; } local $" = ", "; print "Line $.: 'and' appears as word @locations.\n"; } __DATA__ This is a test and a test and a test.
Dave
In reply to Re: tracking words in lines
by davido
in thread tracking words in lines
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |