#! /usr/bin/perl use warnings; use strict; use diagnostics; print "Enter filename to open (text only):\n\n"; my $infile = ; chomp $infile; unless( -f $infile ) { die "Error: file '$infile' is not existing\n"; } open( my $INFILE, '<', $infile ) or die "Error: can't open '$infile' for reading: $!\n"; print "Enter filename to SAVE text file as:\n\n"; my $outfile = ; chomp $outfile; open( my $OUTFILE, '>', $outfile ) or die "Error: can't open '$outfile' for reading: $!\n"; print qq~Enter string to replace "and" with\n\n~; my $word = ; chomp $word; print "\n" x 3; my $count = 0; while( <$INFILE> ) { $count += s/ \band\b /$word/gix; print $OUTFILE $_; } # while close $INFILE or die "Error: can't close '$infile' for reading: $!\n"; close $OUTFILE or die "Error: can't close '$outfile' for writing: $!\n"; print qq~There were $count instances of "and" in '$infile'\n";