sub find_year { my( $str ) = @_; my $year; $year = $1 if( $str =~ /\b((?:19|20)\d\d)\b/ ); return $year } #get the title from csv3 open CSV3, ") { chomp; my ($title) = $_ =~ /^.+?,\s*([^,]+?),/; #/ match the title } for my $title { print $title , " => ", find_year($title), "\n"; }