if $line =~ /train times ([^to ]|[^from ])+/ { do something with line }