use strict; use warnings; #define a regexp matching the interesting variable names my $interesting_vars = qr(a111111111111111111111111|c222222222222222222222222); #sample input rows my @rows = ('a111111111111111111111111 1b8888888888888888888888888 15x222222222222222222222222 2', 'd999999999999999999999999 4b3333333333333333333333333 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; } }