open (FH,$ARGV[0]) or print "could not open file" ; # Better to use the 3-argument version of "open", and lexical file handles : # open ( my $fh, "<", $ARGV[0]) or print "could not open file '$ARGV[0]'; $!"; my $info = ; # This reads ONLY the first line of the file.. # You need to put the file reading into a "while" loop that exits at EOF # Typically, this is written : while (<$fh>){ ..do stuff .. } while ($info=~ /(\w+ (-?\d+ )+)/) # move regex stuff inside the while { my $info =~ s/(\w+ (-?\d+ )+)//; # Careful with spaces inside regexs } my @nums = split(/:/,$info); # These need to be inside the while my $word = shift (@nums); my $sum = 0; my $var = ($info); foreach $var (@nums) # Adding up stuff needs to be inside the while { $sum = $sum + $var; } my %hash = ($word = $sum); # You mean ($word => $sum) print @nums; # try print "@nums\n"; That will space out the numbers, and add a newline.