#!/usr/bin/perl use strict; use warnings; use File::Find; use File::Slurp; my @dir = ( '/work' ); my $term = 'my term'; find( sub{ my @lines; -f and @lines = read_file( $File::Find::name ); # complete pathname to the file for my $line (@lines){ if ($line =~ /\A $term /x){ print $File::Find::dir # Directory name . q{/} . qq{[$_]} # file name . qq{ : $line}, "\n" # line matching the term } } }, @dir );