if ($sentence =~ / () ([a-zA-Z0-9.-_]+)\/([A-Z]+) ([^ ]+) (<\/NP>) /) { $text="NounPhrase"; # to test the match to replace $result =~ s/$question/$text/; print "$result";};