Extract last K characters from a string in Perl

I have a string that looks like this

my $str1 = "ACGGATATTGA";
my $str2 = "alex";

What I want to do is to extract last three characters from each of that.

$out1 = "TGA";
$out2 = "lex";

How can I do it in Perl?

Answers


Use substr:

$out1 = substr($str1, -3);

Need Your Help

Magento - Customer Address Country Dropdown Issue

magento admin magento-1.7 country street-address

I'm using Magento CE 1.7.0.2, having recently upgraded from 1.4.2.0. And when editing/creating a customer address in the backend, the country dropdown field is blank - with no possible options to s...

Valid to use <a> (anchor tag) without href attribute?

html anchor semantic-markup htmlbutton

I've been using Twitter Bootstrap to build a site, and a lot of its functionality depends on wrapping things in &lt;a&gt;, even if they're just going to execute Javascript. I've had problems with the