foreach my $min (20 .. 29) { foreach my $sec (@seconds) { chomp(my $res = `cut -d "|" -f 1,10,13 SMSCDR*$date$hour$minute*.log |grep "Submit|SMPP" |grep "$hour:$min:$sec" |sort |uniq -c`); my $SMPP_count = (split /\s+/, $res)[0]; print $SMPP_count; } }