#!/usr/local/bin/perl # Jaime Prilusky, 2009 my $s4 = shift @ARGV || "the"; $string = join(" ",@ARGV) || qq{There were doors all round the hall, but they were all locked; and when Alice had been all the way down one side and up the other, trying every door, she walked sadly down the middle, wondering how she was ever to get out again.}; while ($string =~ m/$s4/g) { # try also with 'i' as modifier reportHit(pos($string),$`,$&,$'); } sub reportHit { ($pos,$bef,$hit,$aft) = @_; print qq{ POS:$pos $bef>>>$hit<<<$aft }; return; }