thanks this works fine but what if I want to read in a file and do it for every row? I tried playing it around by using the g/ expression but wasn't able to get this to work..To read in the file I am able to do so by

pay an attention that you should not join whole file data into single string because the regex provided will work for first data set only because of '^' (line start) condition in the regex. so it's better to process the file via line by line.

if you'd like to process the data (not to store in csv) you can make the array of arrays (2D matrix) the following way:

place before while() circle my $data = [];

place within while() circle (instead of or in addition to 'print') push @{$data},\@attrs;

then you can access the required row and column via $data->[row-1][column-1]

Would it be possible for me to put in a "if else" function that first counts the number of "characters" in a string and if it exceeds 10 (attributes) first delete an attribute and do nothing on those that have exactly 10 attributes?

So I have some data that are longer than 10 attributes. For example,

MB 1 UL L F UT 100 BL BX P 20 CT

We have 11 attribute and we have to delete BL above to make it MB 1 UL L F UT 100 BX P 20 CT

However, when i run the code, I get MB 1 UL R NF REG L P F UT 85 BL BX P 20CT

due to there could be a lot of conditions and the logic is rather complex using just regular expressions is not flexible and the code is hard to read. So I'd recommend to check all the attributes one by one within the internal circle like following

We have to start with open (INFILE, "< at.txt") || die "can not read: $!"; open (OUTFILE, "> output.csv") || die "can not write: $!";

while (my $string = <INFILE>) {

or simply

$string=<INFILE> ?

Also for if( $current =~ /^BL$/ && $input[0] =~ /(?:BX|P)/ ){ is this simply ignoring BL or also deleting? The problem is that i do not know exactly what these strings would be so i'd like to put a command that says "IF it is NOT equal to XYZ then erase the string"