foreach $key (keys %argument) { $argument{$key} =~ s/\\\\/\\/g; } #### #!/usr/bin/perl use strict; use Getopt::Std; my (%argument, @contents, $contents, $key); getopts('hd:s:', \%argument); foreach $key (keys %argument) { $argument{$key} =~ s/\\\\/\\/g; } if ($argument{h}) { helptext() }else{ open(FILEHANDLE, "< $ARGV[0]") or die "cannot open file: $!"; $contents = do{local $/; }; $contents =~ s/$argument{d}/$argument{s}/g; print $contents; close(FILEHANDLE); } sub helptext { print <<"EOT"; ===== syntax: fts [-h] -d [-s ] -h prints this help text and exits: invoking the help argument causes all other arguments to be discarded by this utility -d takes string as input, searches for that string: replaces with string from -s or with an empty string if no -s argument is specified -s takes string as input, substitutes it for string specified by the -d argument -- if not specified, text matching the -d argument will simply be deleted specifies [path and] name of file to take as input, on whose contents this utility operates description: fts (aka "file text substitution") takes a file's contents as input and operates upon them, doing a simple find and replace operation globally throughout the file. The results are dumped to STDOUT, so the original file is untouched. If you want the original file to be overwritten with the new contents, use a shell redirect. bugs: There are no known bugs at this time. credits: Chad L. Perrin (author) Perlmonks community (contributors) license: This utility released under CCD CopyWrite. See following URL for details. http://ccd.apotheon.org EOT }