$file1{$word}{$site} += $count; #### use strict; my %data; my @filenames = ...; # @ARGV or literal strings or whatever for my $fname ( @filenames ) { open my $input, "<", $fname or die "$fname: $!"; load_data( $input, \%data ); } # doing stuff with %data is left as an exercise... sub load_data { my ( $fh, $href ) = @_; while ( <$fh> ) { next unless ( s/^(.*?):\s*// ); my $word = $1; for my $field ( split ) { my ( $site, $count ) = split /,/, $field; $$href{$word}{$site} += $count; } } }