#!/usr/bin/env perl use strict; use warnings; my $fn = \&doOtherProcessing; while () { if (/for/) {$fn = \&doStage1} if (/their/) {$fn = \&doStage2} if (/fruit/) {$fn = \&doStage3} if (/lazy/) {$fn = \&doOtherProcessing} $fn->($_); } sub doStage1 { print "1: ",shift } sub doStage2 { print "2: ",shift } sub doStage3 { print "3: ",shift } sub doOtherProcessing { print "*: ",shift } __DATA__ now is the time for all good men to come to the aid of their party. Time flies like an arrow fruit flies like a banana. The quick red fox jumps over the lazy brown dog. Etaoinshrdlu.