use strict; use warnings; my @strings = qw{ 0;1;2;3;4;5;6;7;8;9;10;11;12;13 0;1;2;3;4;5;6;7;8;9;10;11;9;8 0;1;2;3;4;5;6;7;8;9;10;11;99 0;1;2;3;4;5;6;7;8;9;10;11;9 0;1;2;3;4;5;6;7;8;;10;11;;13 0;1;2;3;4;5;6;7;8;;10;11;12;13 }; my $rxByPosn = qr {(?x) \A # Start of string (?:[^;]*;){9} # Nine fields/delimiters ([^;]*) # Capture 10th field, which # could be blank ; # Delimiter (?:[^;]*;){2} # Two more fields/delimiters \1 # 13th field must match 10th (?:;|\z) # Delimiter or end of string }; foreach my $string ( @strings ) { print qq{String - $string\n}, $string =~ $rxByPosn ? qq{ Col. 10 matches col. 13\n} : qq{ Cols 10 and 13 differ\n} ; }