$vote = 'somefile.txt'; open (VOTE, "+>>$vote") or die "Cannot open output file: $!\n"; seek VOTE, 0, 0; while () { # you read the votes here and put them into appropriate variables } # increment the voting. seek VOTE, 0, 0; truncate $vote, 0; # print your votes back to the file.