I rewrote the code to find even more matches, here it is, enjoy :-)

use warnings; use 5.014; # mostly for /r my %words = map {chomp; $_=>1} grep {!/'s$/} do { open my $fh, '<', '/usr/share/dict/words' or die $!; <$fh> }; my %search; for my $word (sort keys %words) { next unless $word=~ m{ \A (?<pre> s )? (?<sep> [a-zA-Z0-9] ) (?<search> (?: (?!\g{sep}) . )+ ) \g{sep} (?! \g{search} \g{sep} ) (?<repl> (?: (?!\g{sep}) . )* ) \g{sep} (?<flags> [msixpongr]* ) \z }msx; push @{ $search{$+{search}} }, { word=>$word, %+ }; } my @search = sort { length $b <=> length $a or $a cmp $b } keys %search; my ($re) = map {qr/$_/} join '|', map {quotemeta} @search; for my $word (sort keys %words) { next unless length $word > 1 && $word=~/($re)/; for my $s (@search) { next unless $word=~/\Q$s/; for my $r (@{$search{$s}}) { my $test = eval '$word=~s/\Q$s/$$r{repl}/r'.$$r{flags}; defined $test or die $@; next unless length $test > 1 && exists $words{$test} && $test ne $word; my ($pre,$pat) = ($$r{pre}//'s',$$r{word}); ( $pat = $$r{word} ) =~ s/\A\Q$$r{pre}// if $$r{pre}; my $code = "\$word =~$pre $pat$$r{flags}r"; eval($code) eq $test or die "$code - $test - $@"; say "$word =~$pre $pat => $test"; } } }

But seriously, to respond to Fletch's comments, of course this is just for fun ;-) When I wrote it I was thinking I might try my hand at some Perl poetry some time, unfortunately I don't think I'm creative enough in that way... at least here's some code if anyone else wants to give it a spin ;-)


In reply to Re^7: What does $_ = qq~"$_"~ do? by haukex
in thread What does $_ = qq~"$_"~ do? by mkj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.