fork download
  1. #!/usr/bin/perl
  2.  
  3. use warnings;
  4. use strict;
  5.  
  6. $\ = $/;
  7.  
  8. $_ = <>, chomp;
  9. @_ = map { s/^\s+|\s+$//gr } map { split m/[.]\K\s+(?=[A-Z0-9])/ } split m/[!?]\K/;
  10.  
  11. <>;
  12.  
  13. while(<>){
  14. m/\w/ or next;
  15. # lowercase each word and write it into look-ahead (\b - word boundary):
  16. my $re = join '', map "(?=.*\\b$_\\b)", map lc, m/\w+/g;
  17. my @found = grep m/$re/i, @_; # i = ignore case
  18.  
  19. print "Search results for \"$_\":";
  20. print "- \"$_\"" for @found;
  21. }
Success #stdin #stdout 0s 6188KB
stdin
  abc . If op ? . . Nud . pl ! um isp .  
8
abc
if
nud
isp
op   nud
op if
if o
stdout
Search results for "abc":
- "abc ."
Search results for "if":
- "If op ?"
Search results for "nud":
- "Nud . pl !"
Search results for "isp":
- "um isp ."
Search results for "op   nud":
Search results for "op if":
- "If op ?"
Search results for "if o":