Have a look at perlretut:

What is a regular expression? A regular expression is simply a string that describes a pattern. [...] In Perl, the patterns described by regular expressions are used to search strings, extract desired parts of strings, and to do search and replace operations.
 /($what){3}/;

To have this expression operate on $what, you would need to write it $what =~ /($what){3}/;. But even then, it won't match, because it would try to match the contents of $what 3 times. In this case, you would be better off with the x operator. You probably also want to print a newline at the end:

use 5.012; use warnings; my $what = 'ram' x 3; print $what, "\n";

Or even...

use 5.012; use warnings; say 'what' x 3;

Your code should always use warnings;, and usestrict; or use5.012; (or later), which automatically enables 'strict'. You might usediagnostics as well. All of these will help you understand and avoid many errors.


In reply to Re: simple regular expression printing by rjt
in thread simple regular expression printing by gaurav

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.