#!/usr/bin/perl # xyzatgc.pl # = Copyright 2011 Xiong Changnian = # = 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__ #### XYZATGC XYZATGC XYZATGC XYZATGC XYZATGC XYZ xyz foo ATGC atgc JAPHATGC XYZATGC XYZATGCXYZATGCXYZATGC #### XYZ XYZ XYZ XYZ XYZ XYZ xyz foo ATGC atgc JAPHATGC XYZ XYZXYZXYZ