sub check_file { my $filename = shift; my $string = shift; open(F, "< $filename") or die "$filename: $!"; while() { close(F), return 1 if /\Q$string\E/; } close(F); return } if (search_file('file1', 'string1') && search_file('file2', 'string2')) { print "OK\n"; } else { print "No\n"; }