use strict; use File::Find; my $path = "/somwhere/to"; find (sub { return unless -f;# only files &followup($File::Find::name); }, $path); sub followup { my $contents = slurp($_[0]); if ( $contents =~ /line3/g ) { if ( $contents =~ /(line2-)(\w*)/g print $2; } } sub slurp { local $/ = undef; local *X; open X, $_[0] or die "Can't open $_[0]: $!"; my $slurp = ; close X or die "Can't close $_[0]: $!"; $slurp; }