print reverse($1) . "\n"
if reverse($string) =~ m/(\d{3} :txet)/;
If you wish to prevent strings of digits exceeding a length of 3, you can add a lookbehind:
m/(?<!\d)(\d{3} :txet)/
But now perhaps it's become ugly enough that reverse hasn't bought clarity.
Update: I can't recall where I first saw this technique. I thought maybe Mastering Regular Expressions, but a quick search of that text didn't turn up anything relevant. However, the notion of reversing a string as a quick and easy means of finding the last occurrence of some match in the string is discussed here: http://www.perl.com/pub/2001/05/01/expressions.html.
|