in reply to
Extracting specific data from fixed-width columns
From your description, I am not 100% sure about how your input data is structured, I assume all variables can appear in any one of the three key columns. A working solution would be as follows: (Sorry if it looks strange, I don't know how your data looks and have used your column widths of 25 and 15. I have just printed out the matches, of course you can e.g. save them in a hash or call a function immediately on them, depending on what you want to do with the data.)
use strict;
use warnings;
#define a regexp matching the interesting variable names
my $interesting_vars =
qr(a111111111111111111111111|c222222222222222222222222);
#sample input rows
my @rows = ('a111111111111111111111111 1b8888888888888888
+888888888 15x222222222222222222222222 2',
'd999999999999999999999999 4b3333333333333333
+333333333 15c222222222222222222222222 123');
for (@rows) {
#split by variable value pairs
for (/.{40}/g) {
#split variable and value
/(.{25})(.{15})/;
#since I am doing an additional match, I have to
#save my submatches
my $var = $1;
my $val = $2;
print "'$var' = '$val'\n"
if $var =~ $interesting_vars;
}
}
Output:
'a111111111111111111111111' = ' 1'
'c222222222222222222222222' = ' 123'