I'm not sure you've given enough information. We need a broader selection of example inputs and outputs.
For instance, here's a perfectly valid script that does exactly what you demand -- no more, no less:
#!/usr/bin/perl
# xyzatgc.pl
# = Copyright 2011 Xiong Changnian <xiong@cpan.org> =
# = Free Software = Artistic License 2.0 = NO WARRANTY =
use 5.014002;
use strict;
use warnings;
#~ use Devel::Comments '#####', ({ -file => 'debug.log' });
#---------------------------------------------------------------------
+-------#
# Pass input filename on command line: $ xyzatgc.pl infile.txt
my $in_filename = shift;
# Construct output filename: infile.txt => infile.out
$in_filename =~ /([^.]+)\.txt/;
my $out_filename = $1 . q|.out|;
# Slurp in entire input file.
my $indata ;
{
open my $in_fh, '<', $in_filename
or die "Couldn't open $in_filename for reading";
local $/ = undef; # slurp
$indata = <$in_fh>;
close $in_fh
or die "Couldn't close $in_filename";
};
# Substitute as required.
$indata =~ s/XYZATGC/XYZ/g;
# Write results to output file.
open my $out_fh, '>', $out_filename
or die "Couldn't open $out_filename for writing";
say {$out_fh} $indata;
close $out_fh
or die "Couldn't close $out_filename";
# Terminate.
say 'Done.';
__END__
Input:
XYZATGC XYZATGC XYZATGC XYZATGC XYZATGC
XYZ xyz foo ATGC atgc JAPHATGC
XYZATGC
XYZATGCXYZATGCXYZATGC
Output:
XYZ XYZ XYZ XYZ XYZ
XYZ xyz foo ATGC atgc JAPHATGC
XYZ
XYZXYZXYZ
Now I'm going to wager that's not quite what you want. Please don't try to explain in English words what you'd rather see. Instead, show us a fuller example of input and output.
We'll see what we can do.
I'm not the guy you kill, I'm the guy you buy. —Michael Clayton