use strict; use warnings; use Data::Dumper; my $fname = shift or die "usage: $0 fname\n"; open(my $fh, '<', $fname) or die "error: open '$fname': $!"; # Slurp file contents into string $contents my $contents = do { local $/; <$fh> }; close $fh; # Extract what you want, for example my @words = $contents =~ /\w+/g; # ... or split on what you don't want, for example # my @words = split /\s+/, $contents; # In both approaches above you can tweak the regex to suit # Print out the extracted word list to verify for my $word (@words) { print "word='$word'\n"; } # ... or use Data::Dumper print Dumper( \@words ); # ... or write an automated test with specified input and expected output