use FileHandle; my $fh = \*DATA; bless $fh, 'FileHandle'; if( $fh ) { while ( my $line = $fh->getline ) { print $fh->tell . $line; } }