#!/usr/bin/perl -w use strict; my $number = 1234; my $last2; if ( $number =~ /^\d\d(\d\d)$/ ) { $last2 = $1; } print "$last2\n" if defined $last2;