#!/usr/bin/perl -w package Parser; use strict; sub new { bless {}; } sub add { my $self = shift; my $hash = shift; push @{$self->{parsers}}, $hash; } sub parse { my $self = shift; my $file = shift; open FILE,'<',$file || die "Can't open $file"; while() { foreach my $p (@{$self->{parsers}}) { if(/$p->{start}/ ... /$p->{end}/) { $p->{process}($_) unless (/$p->{start}/ || /$p->{end}/); } } } close FILE; } 1; sub parse1 { my $text = shift; print "Into parse1\n"; print $text; } sub parse2 { my $text = shift; print "Into parse2\n"; print $text; } my $p = Parser::new(); $p->add({ start => "^ ID Lev File/Address", end => "---", process => \&parse1}); $p->add({ start => "^Call *Site *Time *App", end => "---", process => \&parse2}); $p->parse($file);