use strict; use warnings; use Data::Dumper; $Data::Dumper::Indent = 0; my $file = "test"; my @data; { local $/ = undef; open FILE, "$file" or die $!; while (my $line = ) { push @data, split /XXX/, $line; # I thought it should be /^XXX$/, but that didn't work } } @data = grep /\S/, @data; # I don't understand why I had to do this print Dumper \@data;