in reply to Writing in files

One way to do it is to use Tie::File to treat your file as an array, then just prepend a new first line using unshift:
use strict; use warnings; use Tie::File; tie my @array, 'Tie::File', 'file.txt' or die $!; unshift @array, 'new first line'; untie @array;