if ( $css =~ /background-color\s*:\s*#([0-9a-f]{6}|[0-9a-f]{3})\s*;?/i ) { print "background color is $1"; }