- or download this
use strict;
use warnings;
...
my @results = ();
1 while $str =~ s/(.{2}\b$word\b.{2})/push(@results,"$1\n")/e;
print @results;
- or download this
bash> perl resample.pl
A plus B
...
H plus I
4 plus J
5 plus K
- or download this
A plus B
D plus E
...
H plus I
I plus J
J plus K