open $file_fh, "$file" or die "unable to open $file for read : $!"; @lines = <$file_fh> ; foreach $line(@lines) { if ( $line =~ /fred\s+(\w+)\s+barney\s+(\w+)\s+joe\s+(\w+)/i ) { $company = $1 . "_" . $2 . "_" . $3 . "_" . "inc"; # this would assign "flintstone_rubble_rockhead_inc" to $company # but how could I come up with the same string, if the 3 names were in the six possible sequences? # 123, 132, 213, 231, 312, 321 etc,.. # so that it would still assign the word following "fred" as the first capture, the word # following "barney" as the 2nd capture, and the word following "joe" as the 3rd capture, # now matter what order the names are on the line.