my %match = ( 'pattern_one' => [\&sub_one, $results_one], 'pattern_two' => [\&sub_two, $results_two], ); while () { chomp; next unless ( m/(match_pattern)/ ); unless ( $match{$1} ) { #something basic goes here next; } # get the right function from our dispatch table ($func, $results) = [ $match{$1} ]; # now call it, pass it the text to process, and store the # results. $results = &$func($1); } # END while close(F);