open my $RD, '<', 'input.txt' or die "Cannot open 'input.txt' $!"; open my $WR2, '>>', 'output.txt' or die "Cannot open 'output.txt' $!"; my $C = qr/1999-1041/; my $count = 0; while ( <$RD> ) { $count += /$C/; } print $WR2 "$C ", $count ? '' : 'not ', "found in file 'input.txt'.\n";