#!/usr/bin/perl -w open(FILE, "+; seek(FILE, 0, 0) || warn "Seek: $!"; for(@lines) { printf FILE "%-${l}s\n", $_; }