use warnings; use strict; print "Enter a directory:"; chomp( my $dir = ); print "String looked for: "; chomp( my $str = ); chdir $dir or die $!; opendir DH, $dir or die $!; while ( readdir(DH) ) { next if $_ eq '.' or $_ eq '..'; unless (-d) { open my $fh, '<', $_ or die $!; while (<$fh>) { print $_ if /\Q$str/; last; } } } closedir DH or die $!;