This function implements the interface I described in Re^2: Abritrary multiple spaces as delimiter. You call it like so:

unpack_fields( $record, \my $num => 7, padding => 1, \my $title => 27, padding => 1, \my $author => 25, padding => 1, \my $flag1 => 1, padding => 5, \my $flag2 => 1, );

I assume this is self explanatory. :)

# this would be much easier in Perl 6 sub unpack_fields { my $record = shift; my @var; my $template = join " ", map { my ($field, $width) = splice @_, 0, 2; push @var, $field if ref $field; ( ref $field ? 'A' : 'x' ) . $width; } 0 .. $#_ / 2; my @value = unpack $template, $record; ${ shift @var } = shift @value while @value; }