use Data::Dumper; open FH, "sap.txt" or die "$!"; while(){ chomp $_; push(@data,$_); } print Dumper \@data; close FH; __DATA__ $VAR1 = [ '1 2 hello aerf', '1 2 hello aerf', '1 2 hello aerf', '1 2 hello aerf', '1 2 hello aerf', '1 2 hello aerf' ]; #now how I can convert this into the above output