http://www.perlmonks.org?node_id=996626


in reply to pattern sequence dispersed within text

This should do what you want:
#!/usr/bin/perl use warnings; use strict; use feature 'say'; my $word = 'helen'; my $input = 'xxxhexxxxxxxx xle xxnxle nxxx xxnxxx xnxxhexx nxxxxx xlex +xxxxx nxnx xxxx'; my $regex = '([^ \b]*' . join('[^ \b]*).*?([^ \b]*', $word =~ /(..?)/g +) . '[^ \b]*)'; my @matches = $input =~ /$regex/g; say for @matches;
The regex is constructed from the $word dynamically, so you do not have to know the length of it in advance.
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: pattern sequence dispersed within text
by Anonymous Monk on Oct 01, 2012 at 11:53 UTC
    Just in case quotemeta insert  map { "\Q$_\E" }