#!/usr/bin/perl
use strict;
use warnings;

my $filename = shift;
#Strip ARG[0] to filename
my $tempname = $filename . '.tmp';

open(my $fh, '<:encoding(UTF-8)', $filename)
  or die "Could not open file '$filename' $!";
open my $output_h, '>:encoding(UTF-8)', $tempname; 
## Open file and temp file that will contain the strip out password



while (my $row = <$fh>) {
  chomp $row;
	if ($row =~ m/string /) {
		if ($row =~ m/>(.*)</) {
			if (($1 !~ m/^all$/) && ($1 !~ m/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)) {
			#print "antes: "."$row\n";			
			$row =~ s/>(.*)</>redact</;
			#print "despues: "."$row\n";
			#Find 'string' pattern, and ignore 'all' or 'xx.xx.xx.xx' replace the rest with 'redact'		
			}
		}
	}
	#print $row;
	#Write the file with the new edited line
	print $output_h "$row\n";
}