for $station (@stations){ print "\n $station"; print OUTFILE "\n$station"; undef %found; splice @found; for $stage (@stages){ chdir "/opt/stc/db/$station/$stage/prod/doc"; @files = ; for $file (@files){ open HTMFILE, "< $file"; for $line (){ if ($line =~ /${monobj}/ && $line =~ /HREF/ && $line !~ /TOP/){ $found = $stage,$file"; $found{$found} = (split /-/, $line)[0]; } } close HTMFILE; } } @found = sort (keys %found); for $found (@found){ ($stage) = (split /,/, $found)[0]; print "\t- $stage - $found{$found}\n"; print OUTFILE ",$stage,$found{$found}\n"; } print "\n" if ($found[0] eq ""); print OUTFILE "\n" if ($found[0] eq ""); }