#!/usr/local/bin/perl use strict; use warnings; my $string = "This is what you have"; if(substr($string, -14) =~ /have/){ print "You've already a good programmer!!\n"; } substr($string, 0, 5) =~ s/is/at/g; print "$string\n"; #substr($string, 0, 1) ="S"; #print "$string\n"; my $first = substr($string, 0, 1); print "$first\n"; my $a = "make a hat"; print "$a\n"; (substr($a, 0, 1), substr($a, -1)) = (substr($a, -1), substr($a, 0, 1)); print "$a\n"; my $a = "To be or not to be"; my $b = unpack("x6 A6", $a); my $c = unpack("x6 A6", $a); #print $b; ($b, $c) = unpack("x6 A2 X5 A2", $a); print "$b\n$c\n"; sub cut2fmt{ my(@positions) = @_; my $template = ''; my $lastpos = 1; foreach my $place (@positions){ $template .= "A" . ($place - $lastpos) . " "; $lastpos = $place; } $template = .= "A*"; return =$template; } my $fmt = cut2fmt(8, 14, 20, 26, 30); print "$fmt\n";