use Tie::File; my @content; tie (@content, 'Tie::File', $file) or die "Error: couldn't tie $file: $!\n"; # .... and treat the filecontent like an array, e.g. print scalar(@content); # ..... untie (@content);