in reply to
Print only if pattern matches
Your long regex
s/^(.*\|)*.*ABC\.pi=([\d.]+|[\w.]+)*.*ABC\.id=(\d+|[\w.]+).*$/$1$2
+|$3/s;
can be futher reduced to match your required output.
Using the solution provided by
kenosis like so:
use strict;
use warnings;
while (<DATA>) {
next unless /^\d+\|(\d+?)\|/ and $1 == 1;
if (/(.+?)~.+?=(.+?)~.+=(.+?)$/) { # note here
print $1, $2, $3, $/;
}
else {
print "Exception: ", $_, $/;
}
}
__DATA__
123|1|456464|645646|4546|654~abc~dhghga~ABC.pi=112.33.44.55.66~ABC.id=
+789137136770
123|1|456464|645646|4546|654~abc~dhghga~ABC.pi=112.33.44.55.67~ABC.id=
+789134713670
123|1|456464|645646|4546|654~abc~dhghga~ABC.pi=112.33.44.55.68~ABC.id=
+789137213670
123|1|456464|645646|4546|654~abc~dhghga~ABC.pi=112.33.44.55.69~ABC.id=
+78913713670
123|1|456464|645646|4546|654~abc~dhghga~12.33.44.55.70~3713670
123|1|456464|645646|4546|654~abc~dhghga~ABC.pi=112.33.44.55.70~ABC.id=
+78913713670
123|1|456464|645646|4546|654~abc~dhghga~ABC.pi=112.33.44.55.70~ABC.id=
+78913713670
123|1|456464|645646|4546|654~abc~dhghga~ABC.pi=112.33.44.55.70~ABC.id=
+789137135670
123|1|456464|645646|4546|654~abc~dhghga~ABC.pi=112.33.44.55.70~ABC.id=
+789137153670
123|1|456464|645646|4546|654~abc~dhghga~12.33.44.55.70~3713670
123|1|456464|645646|4546|654~abc~dhghga~121322~456466874~8796896
123|2|456464|645646|4546|654~abc~dhghga~121322~456466874~6788708
123|2|456464|645646|4546|654~abc~dhghga~121322~456466874~6806
Output:
123|1|456464|645646|4546|654112.33.44.55.66789137136770
123|1|456464|645646|4546|654112.33.44.55.67789134713670
123|1|456464|645646|4546|654112.33.44.55.68789137213670
123|1|456464|645646|4546|654112.33.44.55.6978913713670
Exception: 123|1|456464|645646|4546|654~abc~dhghga~12.33.44.55.70~3713
+670
123|1|456464|645646|4546|654112.33.44.55.7078913713670
123|1|456464|645646|4546|654112.33.44.55.7078913713670
123|1|456464|645646|4546|654112.33.44.55.70789137135670
123|1|456464|645646|4546|654112.33.44.55.70789137153670
Exception: 123|1|456464|645646|4546|654~abc~dhghga~12.33.44.55.70~3713
+670
Exception: 123|1|456464|645646|4546|654~abc~dhghga~121322~456466874~87
+96896
If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author
unknown to me