#!/usr/bin/perl -w while () { #read a line into $_ chomp; $_ =~ m/^\s*(\S+)\s+(\S+)\s+(\S+)\s+(.*)$/; # col1 col_b xyz Descr my ($col1, $data_b, $xyz, $description ) = ($1, $2, $3, $4); if ( ( $description =~ m/Region/ ) && ( $xyz eq "XYZ" ) ) { $xyz = "N/A"; } print "Line $. = $_\n"; print "\tXYZ result = $xyz \n"; } #end while DATA exit 1; __END__ ValuesInColumn1 DataColumnB XYZ RowDescription|RowCode|Supplier ID::Region ValuesInColumn1 DataColumnB XYZ RowDescription|RowCode|Supplier ID::Region ValuesInColumn1 DataColumnB XYZ RowDescription|RowCode|Supplier ID::Region ValuesInColumn1 DataColumnB XYZ RowDescription at RowCode ValuesInColumn1 DataColumnB ABC RowDescription at RowCode ValuesInColumn1 DataColumnB XYZ RowDescription|RowCode|Supplier ID::HQ ValuesInColumn1 DataColumnB BCD RowDescription|RowCode|Supplier ID::Region