use strict; use warnings; use re q{eval}; my $word = q{test}; my $rxWord = qr{\b$word\b}; # This is the one the does the work. # my $rxWordPos = qr{\b($word)\b(?{print $-[0], q{ }})}; while () { next unless m{$rxWord}; print qq{Match found on line $., column }; while (m{$rxWordPos}g) {;} print qq{\n}; } __END__ This is a test from tester okay nothing message test center test test in proress ... test one test two a tester in this line #### Match found on line 1, column 10 Match found on line 3, column 8 20 Match found on line 4, column 0 20 29 #### use strict; use warnings; my $word = q{test}; my $rxWord = qr{\b($word)\b}; while () { next unless m{$rxWord}; print qq{Match found on line $., column }; while (m{$rxWord}g) { print qq{$-[0] }; } print qq{\n}; } __END__ This is a test from tester okay nothing message test center test test in proress ... test one test two a tester in this line