or download this
#add video tag to video urls inserted without video tag
$text =~ s#(^|\s|\>)((http|https)://www.youtube.com/watch\?\.*v=([a-z0
+-9-_%]+)[&\w;=\+\-]*)#$1\[video\]$2\[\/video\]#isg;
...
#Embed respective video code
$text =~ s#\[video\](http|https)://www.youtube.com/watch\?\.*v
+=([a-z0-9-_%]+)[&\w;=\+\-]*\[\/video\]#<object class="restrain" type=
+"application\/x-shockwave-flash" width="640" height="385" data="http:
+\/\/www\.youtube\.com\/v\/$2"><param name="movie" value="http://www.y
+outube.com/v/$2"/><param name="wmode"
value="transparent"/><embed width="640" height="385" type="app
+lication/x-shockwave-flash" src="http://www.youtube.com/v/$2" /></obj
+ect>#isg;