for my $array(@array) { chomp $array; # may be unnecessary for your aplication if ($array =~ /check-->(\S*\d+)(?:\])$/i) { # \S Not-a-space, /i case insensitive # ^ also un-needed, for data shown, but a precaution # against some possible elements in your __DATA__ my $output = $1; # Good approach; avoids reusing a left-over match