use strict; use warnings; use Math::Combinatorics; # Probably best to get stopwords from a file, but for testing: my @stopwords = qw/ the of in on with by and /; my %stop_hash = map { $_ => 1 } @stopwords; my $term = 'Programming Perl, by Wall, Christiansen and Orwant'; my @term = grep { not $stop_hash{lc $_} } split ' ', $term; # Default highlighting combination: n-1 from n (3 from 4, 5 from 6..) my $n_from = shift || @term - 1; my @combos = combine( $n_from, @term ); my $result = highlight( \@combos, $term ); print join "\n", @$result; sub highlight { my $to_highlight = shift; my $term = shift; my @highlighted; foreach my $combo ( @$to_highlight ) { my $str = $term; # Highlight with Caps for console output # $str =~ s/$_/$_/ for @$combo; $str =~ s/$_/\U$_/ for @$combo; push @highlighted, $str; } return \@highlighted; }