my $packfmt = "A135A11A6A6A20A8A3A978"; my $outline = pack $packfmt, " ", "DATE=${mdy}", ${mdy}, ${hms}, " ", "G1ADP", $CLIENT_ID, " "; # Unpack, trailing blanks preserved (undef, $DMDY, $mdy, $hms, undef, $CLIENT_ID) = unpack $packfmt, $outline; # Unpack 1: remove trailing blanks (same format, but # using map to trim the strings): (undef, $DMDY, $mdy, $hms, undef, $CLIENT_ID) = map { s/\s+$//; $_ } unpack $packfmt, $outline; # Unpack 2: remove trailing blanks, different format my $parsefmt = lc($packfmt); (undef, $DMDY, $mdy, $hms, undef, $CLIENT_ID) = unpack $parsefmt, $outline;