# cut2fmt part 2 sub cut2fmt2 { my(@positions) = @_; my $template = ''; my $lastpos = 1; foreach $fld (@positions) { ($place,$len) = split(/-/,$fld); if ($lastpos<=$place) { $template .= "x" . ($place - $lastpos) . " "; $place += $len; } $template .= "A" . ($len) . " "; $lastpos = $place; } $template .= "A*"; return $template; } # Pick out fields from a fixed length file record # by defining start pos - len eg. 8-3 = get 3 Alpha char from posn 8. # use the string this sub returns in your unpack (or pack!) statement. $fmt = cut2fmt2("8-3","14-6","20-3","26-2","30-1"); print "$fmt\n"; # Returns: x7 A3 x3 A6 x0 A3 x3 A2 x2 A1 A*