Edit: Ignore me please... I need to read the problem completely before whipping out code that doesn't work.
#!/usr/bin/perl
use strict;
use warnings;
my $string = "This is just and example text string to test our regex.
+Please ignore it.";
my $wordpadding = 2;
my $searchword = "test";
$string =~ /((\w+\W+?){$wordpadding}$searchword(\W+?\w+){$wordpadding}
+)/;
print $1;
jdporter unconsidered. Considered by wolfger:
"please delete. I hit send before fully reading/understanding the problem."
Final tally: 8 keep, 11 reap.