To solve your problem I'm going to assume that the number of fields is an even number and that the data values are either 00 or 01. If these assumptions are correct, then you could do something like this:
use strict;
use warnings;
sub pairs_from_line {
my $line = shift;
my @elems = split(//, $line);
my @data;
while (@elems) {
push @data, join('', splice(@elems, 0, 2));
}
return @data;
}
my $line = "0100010100000101000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
my @data = pairs_from_line($line);
my $conversion = 16;
map { print "$conversion," if ($_ == 1); $conversion++ } @data;
This code first converts the input data into a list of pairs (via the pairs_from_line() sub), from which we can convert the binary data into the output values you wish to have. The function works as follows: it splits the input line into its individual elements (split(//, $line)) and creates an array of pairs of these elements by taking two elements at a time (splice(@elems, 0, 2)) and then joining them together via join(). The array of pairs is then returned.
To create the output you want, it's just a matter of iterating over the array of pairs1, printing the value of the conversion factor if the pair evaluates to 12, and updating the conversion factor for each pair as the array of pairs is processed.
1 I've chosen to use a map here, but one could equivalently use a C-style for loop to achieve the same result.
2 Which is what the string "01" will resolve to if it is compared in numeric context, e.g. via the == operator as used in this case; see the Perl documentation about equality operators for more information about which operators to use in string or numeric context.