in reply to Editing the contents of a variable
Better? Who knows? That depends on your intent, your data, etc.
More concise (and less reliance on $_... which is easy to overuse):
my $str = "yada yada <name> string-to-capture </name> foo bar baz";
if ( $str =~ m!<name>(.*?)<\/name>! )
$var1 =~ s/ //g; # removing spaces?
However, if the actual "tags" are intended to be html, xml or suchlike, your "better way" almost certainly involves using an appropriate parser.