my $start_str = "Receive"; my $end_str ="\n"; my @first_loop = grep { /$start_str/../^$end_str$/ ? 1 : 0; } @logs; my @second_loop; my $data = ""; my $k = 0;my $j=0; for(@first_loop){ #first loop is to remove return, head and tail do { $k = 1, next } if $_ =~ /$start_str/; do { $k = 0; push @second_loop, $data; $data = ""; next;} if $_ =~ /^$end_str$/; do { $sctm_data .= $_; chomp $sctm_data; next } if $k == 1; } my @strings; my $refined_logs; my $hex_str; for(@second_loop){ # second loop is to convert and remove [] my $data_str = $_; chomp $data_str; for(split(//, $data_str)) { do { $j = 1, next } if $_ =~ /\[/; do { $j = 0;push @strings, $hex_str; $hex_str = ""; next;} if $_ =~ /\]/; do { $hex_str .= $_; next } if $k == 1; push @strings, sprintf("%02X", ord($_)); } my $last_str = join( " ", @strings ); @strings =(); push @refined_logs, $last_str; }