my %hash; # get data as hash open FILE, $file or die $!\n; while () { my ($key, $value) = split; $hash{$key} = $value; } close FILE; my %changes = ( 'str1' => 'val1', 'str2' => 'val2' ); # change data in hash (or add new elements) $hash{$_} = $changes{$_} for keys %changes # overwrite old file with modified hash open FILE, ">$file" or die $!; print FILE "$_\t$hash{$_}\n" for keys %hash; close FILE;