#!/usr/bin/perl -w use strict; use IO::File; use constant FILENAME => 'filename'; { package cntr; sub TIESCALAR{bless[pop],__PACKAGE__} sub FETCH{ $_[0][0]++ } } my $file = IO::File->new( "< ". FILENAME ) or die "Failed to open '@{[FILENAME]}', $!"; my @elements; { local ( $a, $/ ) = $/.$/; @elements = split $a => <$file>; } $file->close(); print "Here are the elements of the array:\n"; tie my $i, 'cntr', 1; print map {$i.': {'."$_}$/"} @elements;