I think it would be much clearer to use a lookup table (stored in a hash), construct a single capturing regex from the keys of the hash and do a single global substitution operation. It would also be clearer for you and those who come after if you employ a consistent code indentation scheme.

use strict; use warnings; use feature qw{ say }; my %replacementLU = ( QOS_PROFILE_ID => q{x1}, CHARGING_PROFILE_ID => q{x2}, CONTENT_FILTERING_PROFILE_ID => q{x3}, SUBSCRIBERID => q{x4}, RECORD_LENGTH => q{x5}, RECORD_TYPE => q{x6}, EVENT_ID => q{x7}, EVENT_RESULT => q{x8}, CAUSE_PROTOCOL => q{x9}, DEFAULT_BEARER_ID => q{x0}, ARP_PRIORITY_LEVEL => q{y1}, ARP_CAPABILITY => q{y2}, ARP_VULNERABILITY => q{y3}, BEARER_CONTROL_MODE => q{y4}, TRACKING_AREA_CODE => q{y5}, ROUTING_AREA_CODE => q{y7}, SERVICE_AREA_CODE => q{y8}, SYSTEM_IDENTIFIER => q{y9}, NETWORK_IDENTIFIER => q{y0}, GX_RAR_RAA_TRANSACTION => q{TRAR}, GX_CCR_CCA_TRANSACTION => q{TCCA}, QUOTA_GRANTED => q{TQG}, QOS_ASSIGNED_TO_DEFAULT_BEARER => q{TQA}, RULE_INSTALLED => q{TRI}, RULE_REMOVED => q{TRR}, ); my $subsRE = do { local $" = q{|}; qr{(?x) \b ( @{ [ keys %replacementLU ] } ) \b}; }; my $text = q{blurfl,ARP_VULNERABILITY,17,blargle,EVENT_ID,4,glogl}; say $text; $text =~ s{$subsRE}{$replacementLU{ $1 }}g; say $text;

The output.

blurfl,ARP_VULNERABILITY,17,blargle,EVENT_ID,4,glogl blurfl,y3,17,blargle,x7,4,glogl

I hope this is helpful.

Cheers,

JohnGG


In reply to Re: Faster replacement of sed commands.. by johngg
in thread Faster replacement of sed commands.. by Ankur_kuls

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.