#!/usr/bin/perl print "Enter filename:"; chomp($fname = ); # Open the file which contains list of files to be opened. If unsuccessful, print an error message and quit. open (file1,$fname) || die "Can't Open File: $fname\n"; while () { chomp; open (file2, $_); # Open file in the list one by one $temp = $_; # Store the file name to name the corresponding log file print "$temp\n"; # Print the file name to indicate the different output while () { chomp; sub grep_pattern # Print strings which contain the pattern {foreach ($_) {if (/$pattern/) { print "$1\n"; open (file3, ">>$temp.log"); print file3 "$1\n"; # Print result in log file in append mode close (file3); } } } $pattern = 'hello '; # Find the pattern grep_pattern; } print "\n"; # Print a blank line to seperate the results from each file } close (file1);