#!/usr/bin/perl use warnings; use strict; my $first_array = get_words('short.txt'); my $second_array = get_words('woordelysEng.txt'); foreach my $value ( @{$first_array} ) { foreach ( @{$second_array} ) { print $_, " occurs in first text file\n" if $value eq $_; } } sub get_words { my $filename = shift; my @generated_word; open my $fh, '<', $filename or die "can't open file: $!"; while (<$fh>) { push @generated_word, split; } return \@generated_word; }