use strict; use warnings; #my $file = "data.txt"; my $file = \do{my $simulated_file = "line1\nline2\nline3\nline4\n";}; # Line above simulates the file. open (my $fh, '<', $file) or die "can't open file $!"; my @stack = <$fh>; chomp @stack; { local $, = "\n"; print reverse( @stack ), "\n"; } @stack = (); # Only needed if you wish to destroy the @stack OUTPUT: line4 line3 line2 line1