my @strings = ( 'test[abc]test', 'test[cde]test', 'test[ack]test', ); my $regex = qr/ \b\[ # Require a word boundary and match an open bracket. (\w+) # Capture one or more "word" characters. \]\b # Match a close bracket and require a word boundary. /x; foreach my $string ( @strings ) { if( my( $name ) = $string =~ $regex ) { print "$name\n"; } }