#! perl -slw use strict; use List::Util qw[ reduce ]; use Data::Dump qw[pp]; sub normalise { local $_ = lc shift; tr[!"£$%^&*()-_=+'@;:#~/?\|`][]d; #" s[\s+][ ]g; return $_; } my $text = normalise do{ local $/; }; my( $n, %wordPosns ) = 0; $wordPosns{ pos( $text )-1 } = ++$n while $text =~ m[\s+]g; my $quote = normalise 'I want to get a little more sophisticated and allow the user to submit a mildly edited quote.'; my @qwords = split ' ', $quote; my %matches; for my $word ( @qwords ) { while( $text =~ m[\b$word\b]g ) { $matches{ $wordPosns{ pos $text } } = $word ; } } #pp \%matches; my @runs = []; reduce { push @{ $runs[ -1 ] }, $a; push @runs, [] if defined $a and $a+1 < $b; $b; } sort{ $a <=> $b } keys %matches; @runs = grep @$_ > 3, @runs; #pp \@runs; print join ' ', map $matches{ $_ }, @$_ for @runs; __DATA__ #### C:\test>665700 i want to get a little more sophisticated i want the user to to submit a mildly edited quote