use strict; use warnings; while ( my $string = ) { chomp $string; if ( $string =~ m/(\w+)\s((??{"[$1]+"}))/ ) { print "$string => matched: $1, $2!\n"; } else { print "$string => Didn't match.\n"; } } __DATA__ abcde fgh abcde eadcabe