#!/usr/bin/perl use warnings; use strict; # open your file using a filehandle called MYFILE open(MYFILE, "/root/prac/packages/test.txt"); my $data; while () { chomp; print ; #printing each line. Before ending the loop it prints entire file $data = join "", ; } print $data,"\n"; #prints entire file #### 1st line 2nd line 3rd line 4th line End of file #### [root@ems packages]# perl variable_entire_file.pl 2nd line 3rd line 4th line Ending the file