use strict; use warnings; my $string = 'field1 ' . 'field2 ' . 'field3 ' . 'field4 ' . 'field5 ' . 'field6 ' . 'field7 ' . 'field8 ' . 'field9 ' . 'file name here ' . 'field11 ' . 'field12 ' . 'field`3 ' . 'field14 ' . 'field15 ' . 'field16 ' . 'field17 ' . 'field18 ' . 'field19' ."\n" ; my $skip_field = qr /[^\s]+\s+/; # Include any non-whitspace character my $file_field = qr /[\w\s]+/; # Include word characters and spaces my ($file_name) = $string =~ m/\A$skip_field{9}($file_field)\s$skip_field{9}\z/; print $file_name, "\n";