#!/usr/bin/perl -w use strict; while () { #one of many, many ways to get the 8 digit date my ($date) = /(\d{8}).*.log$/; print "$date\n"; } =prints 20111031 // Oct 31, 2011 20110101 // Jan 01, 2011 =cut __DATA__ AAAA*20111031*.log AAAA*sfdaf*20110101*.log