while ( $token=$p->get_token() ) { if ($token->is_start_tag('img') ) { my $src = $token->return_attr->{src}; print "SRC IS $src\n"; #For Debugging $src =~ s/$src/$newsrc/; print "SRC NOW: $src\n"; #For Debugging $token->set_attr('src', $src); }