package TestParsers; sub file_type_A { local $_ = shift; # parameter is full text of file chomp; my @field_labels = qw/date result tester/; # common pieces of data my %field_content; @field_content{@field_labels} = ( split /\|/ )[1,4,6]; return \%field_content; } # more subs for other formats... (B, C, etc) sub new { my $sub_hash = ( 'Gearbox/Integration' => \&file_type_B, 'Gearbox/Assembly' => \&file_type_A, ... 'Brakedrum/Performance' => \&file_type_A, ... # diff. paths might use same func ); return $subhash{$_[0]} }