Like this?
#!/usr/bin/perl use strict; use warnings; use feature qw/say/; while(<DATA>) { chomp; s/<([0-9A-F]+)>/"<" . hex($1) . ">"/eg; say; } __DATA__ JDW-HP 1MVWV93V7j2Hxsa0Ag6 24:00:00 SUBJECT_EXACT _Did you<A0>serve ou +r<A0>country? -New VA Home.Loan Program_ JDW-HP 1MVWV98Ddd4fLsa0Ag6 24:00:00 SUBJECT_EXACT Did.you.serve_our co +untry? New-VA Home<A0>Loan Program_
Output:
$ perl 1095788.pl JDW-HP 1MVWV93V7j2Hxsa0Ag6 24:00:00 SUBJECT_EXACT _Did you<160>serve o +ur<160>country? -New VA Home.Loan Program_ JDW-HP 1MVWV98Ddd4fLsa0Ag6 24:00:00 SUBJECT_EXACT Did.you.serve_our co +untry? New-VA Home<160>Loan Program_ $
For more on the s// (substitution) operator, see e.g. Regexp Quote Like Operators. The above substitution is fairly straightforward; it looks for angle brackets with one of more hex digits in them, and replaces them with the result of a snippet of code that gets evaluated for each match (hence the /e modifier to the regex). The /g modifier makes this a global operation so that all occurrences are given this treatment, not just the first.
In reply to Re: How do i replace one variable with another after searching for a pattern
by AppleFritter
in thread How do i replace one variable with another after searching for a pattern
by Niklaus Mikaelson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |