# slurp file contents my $contents; { local $/ = undef; open(my $handle, '<', "filename") or die("error: $!"); $contents = <$handle>; close $handle; } # split into array on consecutive whitespace my @words = split /\s+/, $contents;