use strict; use warnings; my $re = qr/the\b.*?quick\b.*?fox/; while () { chomp($_); my $text = $_; my $match; while ($text =~ /($re)/) { $match = $1; $text = substr($match, 1); } print "it matches '$match'\n"; } __DATA__ the dog and the bear are quick, but the quick white fox is quicker the quick fox and the brown fox the quick raven and the quick fox the quick yellow fox and the quick fox