use Data::Dump; use strict; use warnings; my $line = qq([AHB_REPORTER][INFO]: action(62,1,0,0,0,0,5,53,9,0,190)D:/XYZ/reg/Tests/Mcu/A_test.cCALL: (null)); my $key = q(a); my %hash = map { $key++ => $_ } grep { $_ != 0 } &{ sub { $line =~ /action\(([^)]+)\)/; split /,/, $1; } }; dd \%hash; __END__ { a => 62, b => 1, c => 5, d => 53, e => 9, f => 190 }