# pseodocode !!! use strict; use warnings; use Text::CSV_XS; # declare early used vars and others my $TOLERANCE = 0.000001; # you can also use constants in Perl.. my %final_datastructure; #verify @ARGV filling @files my @files .. # define a lookup table for different files my %lookup_table{ type_a => \&proc_file_a, type_b => \&proc_file_b, ... } foreach my $file (@files){ # maybe check readbility? or construct the full path.. process_file ($file); } # output the data out_data(\%final_datastructure); # the general sub sub process_file{ my $fname = shift; my $icnt = 0; open my $fh, "<:encoding(utf8)", $fname or die "cannot Open $fname : $!"; # pass the filehandle to specialized subroutines if ($fname eq 'type_a.csv'){ # pass the filehandle by reference proc_file_a(\$fh); } } # the specialized sub sub proc_file_a{ my $fh = shift; my $csv = Text::CSV_XS->new ({ binary => 1 }) or die "Cannot use CSV: ".Text::CSV_XS->error_diag (); while (my $row = $csv->getline ($fh)){ # fill in the destination datastructure.. ... # sub to output the data sub out_data{ ...