Similar to AnomalousMonk's solution but using look-behind and -ahead assertions and tr with the "complement" flag.
use strict; use warnings; open my $logFH, q{<}, \ <<EOD or die qq{open: << HEREDOC: $!\n}; 2009/06/09 10:11:12 read error: file="/path/to/file" reason: gone 2009/06/09 12:43:27 created: file="/path/to/file" EOD while( <$logFH> ) { s{(?<= file=" ) ( [^"]+ ) (?= " )} {do { my $cap = $1; $cap =~ tr{/}{x}c; $cap }}xeg; print; }
The output.
2009/06/09 10:11:12 read error: file="/xxxx/xx/xxxx" reason: gone 2009/06/09 12:43:27 created: file="/xxxx/xx/xxxx"
I hope this is of interest.
Cheers,
JohnGG
In reply to Re: Selectively replacing characters inside a string
by johngg
in thread Selectively replacing characters inside a string
by markkawika
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |