#!/usr/bin/perl use Data::Dumper; use strict; #use re 'debug'; my $foo_year = "2004-11-12 12:40:42"; test($foo_year); test($foo_year); test($foo_year); sub test { my ($date) = @_; print $date,"\n"; my ($year,$month,$day); $date =~ m/ (\d+) (?{ $year = $^N }) - (\d+) (?{ $month = $^N }) - (\d+) (?{ $day = $^N }) /x; print "$year-$month-$day\n"; }