use 5.008; use strict; use warnings; use Encode qw( encode decode ); use File::Temp qw( tempfile ); use File::ReadBackwards qw(); # Pick a random filename (undef, my $filename) = tempfile(); # Create some content for an example { open my $fh, ">:encoding(UTF-32LE)", $filename or die "can haz file?? $!"; print $fh "$_\n" for qw/ foo bar baz /; close $fh; } # Now let's open it. Note that we need to tell File::ReadBackwards # that the line seperator is the UTF-32-encoded version of "\n". my $fh = "File::ReadBackwards"->new( $filename, encode("UTF-32LE", "\n") => 0, ) or die "can haz file?? $!"; # Read each line while (defined(my $line = $fh->readline)) { # Need to decode line from UTF-32 to Perl's internal encoding $line = decode("UTF-32LE", $line); print "GOT: $line"; } # Delete our temp file unlink $filename;