#!/usr/bin/perl use strict; use warnings; my ($message, $spacing); if ($#ARGV >= 1) { $message = shift; $spacing = shift; } else { die "Usage: els_find.pl message spacing files\n"; } $spacing > 0 or die "Spacing must be greater than zero\n"; # Build a pattern that will recognize the message in regular # text, ignoring punctuation and spacing. my @letters = split //,$message; my $pattern = join("(?:[^a-z]*[a-z]){$spacing}",@letters); my $re = qr/($pattern)/i; # Allow minimal wrapping across lines without having to slurp # the whole file. $/ = ''; # paragraph mode while (<>) { chomp; if ($_ =~ $re) { print "Matched: *$1* at paragraph $. of file $ARGV\n"; } }