#! /usr/bin/perl -w use strict; # Normally a match is made against $_. # If you want to match against another string, use the binding # operator, =~ # Here are some examples: my $string = 'abc'; $string =~ /.(.)./; my $what_is_this = $1; # Notice that no change happened in $string: print "\$string=$string, \$what_is_this=$what_is_this\n"; # see what the substitution operator does: $string =~ s/b/B/; print "\$string=$string\n"; # with no g modifier: $string =~ s/./Z/; print "\$string=$string\n"; # Now see what adding the g modifier does: $string =~ s/./X/g; print "\$string=$string\n"; # $ ./show-match # $string=abc, $what_is_this=b # $string=aBc # $string=ZBc # $string=XXX