use Tie::File; tie @array, 'Tie::File', filename or die ...; $array[2] = 'XXX'; $array[3] = 'YYY'; $array[4] = 'ZZZ'; untie @array;