#!/usr/bin/perl -w use strict; #declare vars my $dir_to_process; #sclar to hold directory location my $file; #sclar to hold file names my %stuff_to_store; #hash of directory locations and file names $dir_to_process = "." ; #defining starting directory location opendir DH,$dir_to_process or die "Cannot open $dir_to_process for processing: $!"; #opening dir to process foreach $file (readdir DH) { #cycling through the directory if ($file =~ /\.txt$/) { #looking for file ext .txt open(my $fh, $file) or die "Unable to open '$file' for reading: $!"; #reading .txt files while (<$fh>) { #cycling through to find happy if (/happy/) { #if its happy then store it in hash stuff_to_store with file location %stuff_to_store = ($dir_to_process, $file); while (%stuff_to_store) { #see if it worked and print out each element of hash stuff_to_store print; #its not working and I don't know why } } } close ($fh); } } closedir DH;