use strict; use warnings; my( @strings ) = ( 'data to gbsdff03dfif7 is', 'data to HR620-Asdf2', 'data to HP650dfgd-Af452 is' ); foreach my $line ( @strings ) { print "Matched $line.\n" if $line =~ /to (.*?) is/i; } #### Matched data to gbsdff03dfif7 is. Matched data to HP650dfgd-Af452 is.