in reply to Regexp help

You are not using the anchors ^ and $ correctly. As it says in perlretut:

Sometimes, however, we'd like to specify where in the string the regexp should try to match. To do this, we would use the anchor metacharacters ^ and $ . The anchor ^ means match at the beginning of the string and the anchor $ means match at the end of the string, or before a newline at the end of the string.

You also misplaced your parentheses assuming you do not wish to capture leading and trailing :. You will get your expected result with

$str = "R4:abcxyz45:LNX"; $str =~ /^[\w\d]+:([\w\d]+):\w+$/;

or

$str = "R4:abcxyz45:LNX"; $str =~ /[\w\d]+:([\w\d]+):\w+/;

or even

$str = "R4:abcxyz45:LNX"; $str =~ /:([\w\d]+):/;
depending on your needs.

Replies are listed 'Best First'.
Re^2: Regexp help
by toolic (Bishop) on Sep 03, 2010 at 16:48 UTC
    ... and simplifying even further to
    $str =~ /:([\w]+):/;

    Since \d is a subset of \w, [\w\d] is the same as [\w].

    Then the square brackets are also not needed:

    $str =~ /:(\w+):/;
Re^2: Regexp help
by Anonymous Monk on Sep 03, 2010 at 16:31 UTC

    my bad ... really my bad.silly mistake :). I got it. Thanks a lot Kenneth. Happy Weekend.