1  请用perl在屏幕输出hello,world

[root@localhost perl]# cat perlhello.pl 
#!/usr/bin/perl
print "hello,world!\n";
[root@localhost perl]# ./perlhello.pl 
hello,world!

2  截取出正则的匹配内容,在shell中,真是头都大了

#!/usr/bin/perl -w
$_="<span class=\"title\">Counter-Strike Global Ofensive</span>";
if(/<span class=\"title\">(.*)<\/span>/)
{
print "$1\n";
}
[root@localhost perl]# ./perlre.pl 
Counter-Strike Global Ofensive

稍微改动下,截取括号的内容,也是很简单

#!/usr/bin/perl -w 

#注意每一句以分号结尾,注意是否转义

$_="(Counter-Strike Global Ofensive)";
if(/\((.*)\)/)
{
print "$1\n";
}

3  接受标准输入,并输出

#!/usr/bin/perl -w
while (<>)
{print;}

[root@localhost perl]# ./receive.pl 

hello,i am liuliancao

hello,i am liuliancao

4 计算圆的面积

#!/usr/bin/perl -w
print "please input the radius of the circle";
$r=<STDIN>;
if($r lt 0)
{$c=0;}
else
{$c=2*$r*3.141592654;}
print "the c is $c\n";
[root@localhost perl]# ./circle.pl 
please input the radius of the circle:1  
the c is 6.283185308

5 计算两个数的乘积,并输出它们

#!/usr/bin/perl -w
print "please input two number divided by Enter,and i will mutiply them\n";
chomp($a=<STDIN>);
$b=<STDIN>;
print "a is $a, and b is $b and  the muti result is ",$a*$b," !\n";

[root@localhost perl]# ./muti.pl 

please input two number divided by Enter,and i will mutiply them

2

5

a is 2, and b is 5

 and  the muti result is 10 !

6 重复输出指定次数字符串

#!/usr/bin/perl -w
print "please input string and times divided by Enter!\n";
chomp ($a=<STDIN>);
$b=<STDIN>;
$result=$a x $b;
print "result is $result\n";
[root@localhost perl]# ./stringtimes.pl 
please input string and times divided by Enter!
liuliancao
5
result is liuliancaoliuliancaoliuliancaoliuliancaoliuliancao