String Extraction in Perl

I have a string stored in a variable. For instance,

$str = " Opcode called is : CM_OP_xxx "
where xxx changes dynamically and can be either LOGIN or SEARCH..... depends on runtime.
For example :
$str = " Opcode called is : CM_OP_SEARCH "
$str = " Opcode called is : CM_OP_LOGIN "

I want to display all CM_OP_xxx only, from $str on the console using "PERL".

Sample output:
-----------------
CM_OP_SEARCH
CM_OP_ACT_LOGIN

$
$ echo " Opcode called is : CM_OP_SEARCH " | perl -lne '/: (.*) / && print $1'
CM_OP_SEARCH
$
$ echo " Opcode called is : CM_OP_LOGIN " | perl -lne '/: (.*) / && print $1'
CM_OP_LOGIN
$
$

tyler_durden

Thanks..
if the string contains " Opcode called is : CM_OP_SEARCH input fucntion"
but if i execute the above statement,
echo " Opcode called is : CM_OP_SEARCH input fucntion" | perl -lne '/: (.*) / && print $1'
the output is coming as "CM_OP_SEARCH input" instead of CM_OP_SEARCH.
Please let me know how to execute this.

2nd Doubt is i want a perl script... how do i embed this in a perl script.

change the perl one liner to

perl -lne '/: (.*?)\s+.* / && print $1'

The above command is command line perl .
if you want to execute it through a script instead of command line use the following

my $str = " Opcode called is : CM_OP_xxx ";
print "$1\n" if ($str =~ m/.*: (.*?)\s+.*/);

HTH,
PL