use strict; my $msg= "INVITE sip:paka@36.212.176.92 SIP/2.0 To:samir Via: SIP/2.0/udp 36.212.176.90:5060;branch=z9hG4bk_Vn Via: SIP/2.0/udp 36.212.176.66:5060;branch=z9hG4bk_oo From: sanjay Call-ID: _Vn8TZTk2H@36.212.176.90 CSeq: 215 INVITE Max-Forwards: 70 Contact: sanjay"; my @fields = split /\n/, $msg; my %config = ( URI => { regex => qr/^INVITE\ssip:/}, To => { regex => '^To:'}, From => { regex => '^From:'}, Via => { regex => '^Via:'}, Via1 => { regex => '^Via:'}, Call_ID => { regex => '^Call-ID:'}, CSeq => { regex => '^CSeq:'}, MaxForwards => { regex => '^Max-Forwards:'}, Contact => { regex => '^Contact:'}, ); my %cnf; foreach (@fields) { chomp; foreach my $c (keys %config) { if (/$config{$c}{regex}/) { $cnf{$c} = $_; last; } } }