note
Kenosis
<p>Yes, that helped! Here's one option that substitutes the "_" with ".+" for use in a regex (use "." if you want only one letter to match):</p>
<c>
use strict;
use warnings;
my @array1 = qw (fil_ t_xt _erl);
my @array2 = qw (Merlin file text fils perl filled);
for my $stem (@array1) {
my $re = $stem;
$re =~ s/_/.+/;
/\b$re\b/ and print "$stem: $_\n" for @array2;
}
</c>
<p>Output:</p>
<c>
fil_: file
fil_: fils
fil_: filled
t_xt: text
_erl: perl
</c>
<p>Only whole words are matched, as word boundires (<c>\b</c>) are used in the regex which, if omitted, will also match substrings within the dictionary words.</p>
<p>Hope this helps!</p>
<p><strong>Update:</strong> Below is an updated version which adapts [http://perlmonks.org/index.pl?node_id=171588|BrowserUk]'s preferred solution:</p>
<c>
use strict;
use warnings;
my @array1 = qw (fil_ t_xt _erl);
my @array2 = qw (Merlin file text fils perl filled);
my $words = join ' ', @array2;
for my $stem (@array1) {
my $re = $stem;
$re =~ s/_/./;
print "$stem: $1\n" while $words =~ /\b($re)\b/g;
}
</c>
<p>Output:</p>
<c>
fil_: file
fil_: fils
t_xt: text
_erl: perl
</c>
<p>If you want the "_" to be matched by more than one letter in the dictionary words, change the substitution to <c>$re =~ s/_/\\S+/;</c>.</p>
1019063
1019072